If a variable is only used in an assert
, then compilers usually produce a warning when the program is compiled in release mode (i.e. without debug flags). This question suggests ways to disable these particular warnings. Among the answers, the C++17 attribute maybe_unused
is suggested. However, these answers have not really been discussed.
Are there any drawbacks to using [[maybe_unused]]
in situations like this one
[[maybe_unused]] const auto i = get_i();
assert(i == 5);
in order to silence the warning about i
being unused in a release build?