https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79510
Bug ID: 79510 Summary: #pragma GCC diagnostic pop/push/ignored doesn't work as expected in template code Product: gcc Version: 6.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: p.chevalier at psenterprise dot com Target Milestone: --- Created attachment 40739 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40739&action=edit main.cxx If a line of code in a template function would trigger a warning, surrounding it with #pragma push/ignored/pop doesn't work. The warning still appears at the call site of the template function, where it gets instantiated. Using clang 3.9.1 with the exact same scenario doesn't exhibit the bug. To reproduce, compile the following main.cxx: -------------------------------------------------------------------------------- #include <iostream> template <typename... T> void print_tuple(T... args) { #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-variable" #else #ifdef __gcc__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-variable" #endif #endif // We use the braced initialization list to expand the parameter pack // apply is unused on purpose auto apply = {(std::cout << args << " ", 0)...}; #ifdef __clang__ #pragma clang diagnostic pop #else #ifdef __gcc__ #pragma GCC diagnostic pop #endif #endif std::cout << std::endl; } int main() { print_tuple("clang++", "--std=c++14", "-Wall", "-Werror", "main.cxx", "✓"); print_tuple("g++", "--std=c++14", "-Wall", "-Werror", "main.cxx", "✗"); print_tuple("g++", "complains", "where", "print_tuple", "is", "called"); } -------------------------------------------------------------------------------- g++ --std=c++14 -Wall -Werror main.cxx produces the following output: main.cxx: In instantiation of ‘void print_tuple(T ...) [with T = {const char*, const char*, const char*, const char*, const char*, const char*}]’: main.cxx:29:80: required from here main.cxx:16:10: error: unused variable ‘apply’ [-Werror=unused-variable] auto apply = {(std::cout << args << " ", 0)...}; ^~~~~ cc1plus: all warnings being treated as errors