https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99974
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- Here's another test case that shows a similar inconsistency between a function declaration at local scope and a subsequent one at file scope, as well as an inconsistency between the C and C++ front ends. G++ fails to diagnose the the conflicting attribute on the redeclaration of f2 (the C front end does the right thing). $ (set -x && cat z.c && gcc -O2 -S -Wall -xc z.c && gcc -O2 -S -Wall -xc++ z.c) + cat z.c __attribute__ ((alloc_size (1))) int* f1 (int, int); __attribute__ ((alloc_size (2))) int* f1 (int, int); // -Wattributes (good) void g (void) { __attribute__ ((alloc_size (1))) int* f2 (int, int); } __attribute__ ((alloc_size (2))) int* f2 (int, int); // C++ missing -Wattributes + gcc -O2 -S -Wall -xc z.c z.c:4:1: warning: ignoring attribute ‘alloc_size (2)’ because it conflicts with previous ‘alloc_size (1)’ [-Wattributes] 4 | f1 (int, int); // -Wattributes (good) | ^~ z.c:2:1: note: previous declaration here 2 | f1 (int, int); | ^~ z.c:13:1: warning: ignoring attribute ‘alloc_size (2)’ because it conflicts with previous ‘alloc_size (1)’ [-Wattributes] 13 | int* f2 (int, int); // C++ missing -Wattributes | ^~~ z.c:9:3: note: previous declaration here 9 | f2 (int, int); | ^~ + gcc -O2 -S -Wall -xc++ z.c z.c:4:13: warning: ignoring attribute ‘alloc_size (2)’ because it conflicts with previous ‘alloc_size (1)’ [-Wattributes] 4 | f1 (int, int); // -Wattributes (good) | ^ z.c:2:1: note: previous declaration here 2 | f1 (int, int); | ^~