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?
You can suppress warning about unused variable this way:
int main(int /* argc */, char** argv)
{
//...
}
or using following trick:
int main(int argc, char** argv)
{
(void)argc;
//...
}
In this case this code will work for earlier versions of C++ standard and even for pure C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With