Add BYN_WARN_UNUSED macro and apply to Name and IString - #8973
Conversation
| namespace wasm { | ||
|
|
||
| struct IString { | ||
| struct BYN_WARN_UNUSED IString { |
There was a problem hiding this comment.
This feels odd to me, to scatter these throughout the codebase. Is there no global flag we can set?
There was a problem hiding this comment.
I mean its kind of like llvm/llvm-project#203084.
If there was a flag I guess it would be something like "-falways-assume-ctors-have-no-side-effects" but I'm pretty sure that is never always true so you wouldn't want it to be global.
There was a problem hiding this comment.
Oh, I see, so this is for the ctors? Can we annotate the ctors directly, then, not the entire class?
There was a problem hiding this comment.
It seems like the way to do this is to annotate the class itself.
Annotating a C++ class with [[gnu::warn_unused]] tells the compiler to issue a -Wunused-variable warning if a variable of that type is instantiated but never explicitly used.
There was a problem hiding this comment.
Is this documented somewhere? I can't seem to find GNU docs.
There was a problem hiding this comment.
The clang docs describe it: https://clang.llvm.org/docs/AttributeReference.html#warn-unused
"""
This attribute is available in both C and C++ language modes but is primarily useful in C++ for classes which have a non-trivial constructor or destructor but act as a value type rather than an RAII type.
"""
There was a problem hiding this comment.
Thanks... funny that it is a gnu thing but clang documents it 😄
Define `BYN_WARN_UNUSED` using `[[gnu::warn_unused]]` for GCC/Clang and fallback for other compilers. Annotating `IString` and `Name` with this attribute allows compilers to report unused variable diagnostics for default-constructed instances regardless of non-trivial constructors. Followup to #8972. Once this lands we can extend this to other types to get better coverage.
|
Funnily enough I couldn't fine any other classes in binaryen what had latent unused variables like the ones in this PR. |
Define
BYN_WARN_UNUSEDusing[[gnu::warn_unused]]for GCC/Clang and fallback for other compilers. AnnotatingIStringandNamewith this attribute allows compilers to report unused variable diagnostics for default-constructed instances regardless of non-trivial constructors.Followup to #8972.
Once this lands we can extend this to other types to get better coverage.