I like the [[maybe_unused]]
attribute and use it a lot when I need to compile out debug-only function implementations. I am a little confused where it should be used when specifying member function arguments as [[maybe_unused]]
.
Given:
//Foo.h
class Foo {
void DebugOnly(Bar& fly);
}
//Foo.cpp
void Foo::DebugOnly(Bar& fly) {
#ifdef _DEBUG
fly.squish();
#endif
}
Does specifying it in both places make a difference?
//Foo.h
class Foo {
void DebugOnly([[maybe_unused]] Bar& fly);
}
//Foo.cpp
void Foo::DebugOnly([[maybe_unused]] Bar& fly) {
#ifdef _DEBUG
fly.squish();
#endif
}
Or should I only declare it in the header or implementation file?
Header-only
//Foo.h
class Foo {
void DebugOnly([[maybe_unused]] Bar& fly);
}
//Foo.cpp
void Foo::DebugOnly(Bar& fly) {
#ifdef _DEBUG
fly.squish();
#endif
}
Implementation-file-only
//Foo.h
class Foo {
void DebugOnly(Bar& fly);
}
//Foo.cpp
void Foo::DebugOnly([[maybe_unused]] Bar& fly) {
#ifdef _DEBUG
fly.squish();
#endif
}
The page on cppreference does not make a distinction for function arguments and only classifies them as "variables".