https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84294
Bug ID: 84294 Summary: missing warning for ignored attribute on a function template declaration Product: gcc Version: 8.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: --- With bug 81544 resolved, GCC 8 warns on distinct declarations of the same function with mutually exclusive attributes (such as const and pure). In the test case below this warning detects the conflict between the two declarations of function f (and the uses of the function in ff() show that GCC does ignore the pure attribute on the second declaration). However, when the same pair of mutually exclusive attributes is specified on declarations a function template GCC issues no such warning, even though it also ignores the conflicting attribute as in the non-template case as the dump shows. $ cat u.C && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout u.C [[gnu::const]] int f (); [[gnu::pure]] int f (); // Wattributes, pure ignored (good) void ff (int *p) { int i0 = f (); *p = 123; int i1 = f (); if (i0 != i1) // folded to false (good) __builtin_abort (); } template <class T> [[gnu::const]] T g (); template <class T> [[gnu::pure]] T g (); // pure ignored, warning missing void gg (int *p) { int i0 = g<int>(); *p = 123; int i1 = g<int>(); if (i0 != i1) // folded to false __builtin_abort (); } u.C:2:22: warning: ignoring attribute ‘pure’ because it conflicts with attribute ‘const’ [-Wattributes] [[gnu::pure]] int f (); // Wattributes, pure ignored (good) ^ u.C:1:20: note: previous declaration here [[gnu::const]] int f (); ^ ;; Function ff (_Z2ffPi, funcdef_no=0, decl_uid=2355, cgraph_uid=0, symbol_order=0) ff (int * p) { <bb 2> [local count: 1073741825]: *p_2(D) = 123; return; } ;; Function gg (_Z2ggPi, funcdef_no=3, decl_uid=2366, cgraph_uid=1, symbol_order=1) gg (int * p) { <bb 2> [local count: 1073741825]: *p_2(D) = 123; return; }