https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79585
Bug ID: 79585 Summary: spurious -Wunused-variable on a pointer with attribute unused in function template Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- While testing a patch for bug 79548 I came across the following inconsistency. The program is expected to compile with no warnings. $ (set -x && cat t.C && for lang in c c++; do gcc -O2 -S -Wunused -x$lang t.C; done) + cat t.C void f () { int i __attribute__ ((unused)) = 0; int __attribute__ ((unused)) j = 0; int* p __attribute__ ((unused)) = 0; int* __attribute__ ((unused)) q = 0; } #if __cplusplus template <class T> void g () { T a __attribute__ ((unused)) = 0; T __attribute__ ((unused)) b = 0; T* p __attribute__ ((unused)) = 0; T* __attribute__ ((unused)) q = 0; } template void g<int>(); #endif + for lang in c c++ + /build/gcc-git/gcc/xgcc -B /build/gcc-git/gcc -O2 -S -Wunused -xc t.C + for lang in c c++ + /build/gcc-git/gcc/xgcc -B /build/gcc-git/gcc -O2 -S -Wunused -xc++ t.C t.C: In instantiation of ‘void g() [with T = int]’: t.C:23:22: required from here t.C:19:31: warning: unused variable ‘q’ [-Wunused-variable] T* __attribute__ ((unused)) q = 0; // bogus warning ^