You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
In many places in the code, there are various implementations of the [[maybe_unused]] behaviour which is unfortunately unavailable before C++17. My idea is to implement _CCCL_MAYBE_UNUSED macro that would be used in these cases instead.
Describe the solution you'd like
The macro could be implemented like this:
#if _CCCL_STD_VER >= 2017 && _CCCL_HAS_CPP_ATTRIBUTE(maybe_unused)
# define_CCCL_MAYBE_UNUSED [[maybe_unused]]
#elif defined(_CCCL_COMPILER_MSVC)
// MSVC has no equivalent to [[maybe_unused]], this is the best we can do
# define_CCCL_MAYBE_UNUSED _CCCL_DIAG_PUSH _CCCL_DIAG_SUPPRESS_MSVC(4100410141894505) _CCCL_DIAG_POP
#else// ^^^ _CCCL_COMPILER_MSVC ^^^ / vvv !_CCCL_COMPILER_MSVC vvv
# define_CCCL_MAYBE_UNUSED__attribute__((__unused__))
#endif // ^^^ !_CCCL_COMPILER_MSVC ^^^
In C++17 we can just use the [[maybe_unused]] attribute. Otherwise with GCC, Clang, NVHPC and Intel compilers its easy, we can just use __attribute__((unused)). However, MSVC does not implement such behaviour. I tried to improvise with diagnostics - allowing and disabling the diagnostic warnings seems to work, with the fact that the disabled warnings are applied to the whole line instad of a single statement.
Is this a duplicate?
Area
General CCCL
Is your feature request related to a problem? Please describe.
In many places in the code, there are various implementations of the
[[maybe_unused]]
behaviour which is unfortunately unavailable before C++17. My idea is to implement_CCCL_MAYBE_UNUSED
macro that would be used in these cases instead.Describe the solution you'd like
The macro could be implemented like this:
In C++17 we can just use the
[[maybe_unused]]
attribute. Otherwise with GCC, Clang, NVHPC and Intel compilers its easy, we can just use__attribute__((unused))
. However, MSVC does not implement such behaviour. I tried to improvise with diagnostics - allowing and disabling the diagnostic warnings seems to work, with the fact that the disabled warnings are applied to the whole line instad of a single statement.Here is a link with some test code: https://godbolt.org/z/jrnE8eq7e
I am mostly focusing on unused variables and functions,
[[maybe_unused]]
can be used in many other places.Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: