This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/79510] New: #pragma GCC diagnostic pop/push/ignored doesn't work as expected in template code
- From: "p.chevalier at psenterprise dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 14 Feb 2017 14:12:41 +0000
- Subject: [Bug c++/79510] New: #pragma GCC diagnostic pop/push/ignored doesn't work as expected in template code
- Auto-submitted: auto-generated
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