C++17 introduces the attribute [[maybe_unused]].
I assume this a standardized version of GCC and Clang's: __attribute__((unused)).
For unused functions that I don't want to see a warning from,
should I be specifying the attribute on
function declarations?
void maybe_used_function() [[maybe_unused]];
or function definitions?
void maybe_used_function() [[maybe_unused]] {
/* impl */
}
Either one? Both?
Will the effect be the same on both the standardized and compiler specific attributes?
I can't find any clear documentation on placement behaviour, and what the common practice is.
When I place the attribute before the function body in a definition, GCC and clang give an error:
void function();
int main(){}
void function() __attribute__((unused)) {}
warning: GCC does not allow 'unused' attribute in this position on a function definition [-Wgcc-compat] void function() __attribute__((unused)) {
However, the attribute can be placed in two other places without error:
__attribute__((unused)) void __attribute__((unused)) function() {}
Maybe one of these ways is how I'm expected to use the attribute on function definitions?