https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69967

            Bug ID: 69967
           Summary: #pragma GCC diagnostic ignored being ignored for
                    -Wunused-variable in some cases
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yaghmour.shafik at gmail dot com
  Target Milestone: ---

Given the following example:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#include <boost/filesystem/operations.hpp>
#pragma GCC diagnostic pop

int main()
{
}

and the following command line options:

  --std=c++11 -Wno-deprecated-declarations -Wunused-variable -Werror -O2

gcc 5.3 produces the following diagnostics:

error: ‘boost::system::posix_category’ defined but not used
[-Werror=unused-variable]
     static const error_category &  posix_category = generic_category();
                                    ^

error: ‘boost::system::errno_ecat’ defined but not used
[-Werror=unused-variable]
     static const error_category &  errno_ecat     = generic_category();
                                    ^

rror: ‘boost::system::native_ecat’ defined but not used
[-Werror=unused-variable]
     static const error_category &  native_ecat    = system_category();
                                    ^


even though it should be ignored due to the:

  #pragma GCC diagnostic ignored "-Wunused-variable"

You can find an online example that reproduces this here
http://melpon.org/wandbox/permlink/LhOgWD7JOFrf95ZQ

This issue only shows up when optimization is turned on with -O1 or above.

GCC 4.9.2 and 6.0.0 do not have this issue. In the case of GCC 6.0.0 it is hard
to tell if the issue is fixed since the diagnostic does not show up all even
when reduce the test case to the following:

#include <boost/filesystem/operations.hpp>

int main(){}

So in 6.0.0 the warning appears to be less aggressive but now we don't know if
the underlying issue with the pragma is fixed or just hidden by change in
behavior of the warning.

Reply via email to