I am trying to ignore the unused parameter
warning using the new c++17 attribute [[maybe_unused]]
, as below.
int main([[maybe_unused]] int argc, char** argv)
{
//...
}
But I still get warning: unused parameter ‘argc’ [-Wunused-parameter]
with the following additional warning.
warning: ‘maybe_unused’ attribute directive ignored [-Wattributes]
I'm using g++ (GCC) 7.2.0
with cmake-3.11.3
. My compiler flags are as follows.
-std=c++17 -Wall -pedantic -Wextra -Weffc++
I remember using this attribute successfully before, but I have no idea why this is not working now. Could someone show what I am doing wrong here?
[[maybe_unused]]
. Works just fine on g++ 7.2 over here however: godbolt.org/g/7KnuDx Double check the compiler version, and the compiler flags that are actually used by the generated makefile. That said, as StoryTeller points out,[[maybe_unused]]
is redundant in a function argument, since you can simply leave it unnamed instead. – Japan