-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use [[nodiscard]]
on ScopeGuard
#5224
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how this would help with the most common use case/user error, see https://godbolt.org/z/EfvGba7K6.
We would only warn for a function returning ScopeGuard
and not storing its return type but constructing an unnamed object of type ScopeGuard
wouldn't raise a warning.
Right, it's unfortunately compiler-specific how well the attribute is taken into account. clang uses it for warnings even if the attribute is only used at the class definition. I could also mark the constructors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to help at least with clang
, see https://godbolt.org/z/Tv49qnPT8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having also the constructor as [[nodiscard]] indeed seems to help at least for clang++, g++, and msvc, see https://godbolt.org/z/absMzfoW7. Please add it there, too.
f3a64fe
to
07d0495
Compare
Force-pushed to also mark the constructors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
One of the CUDA builds yields bogus warnings
|
Withdrawing until issue with warnings is resolved
According to https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations#nodiscard, we should use
|
Thanks for looking that up. Pushed that change but I haven't checked locally if nvcc reports that correctly... |
Guarded by both In principle there could be also a separate macro to use the |
94f620b
to
94fabf9
Compare
I think we should also provide the macro when |
What I meant is that one could have:
That would avoid having the |
We will require C++17 after the 3.7 release anyway and can then replace the current I'm fine with adding
if you prefer that over having the condition at both constructors but wouldn't want to add a macro that users would be encouraged to use downstream. |
94fabf9
to
468ad31
Compare
Fair enough. In that case it's simpler to just put the ifdefs at the constructors. I've updated this accordingly. |
Unsure if I'm supposed to include
Kokkos_Macros.hpp
directly for the macro or if it's enough to get it throughKokkos_Core_fwd.hpp
.