[Bug c++/99974] attributes not propagated across function redeclarations at local scope
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99974 Martin Sebor changed: What|Removed |Added See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=100068 --- Comment #4 from Martin Sebor --- See also pr100068 for another slightly different example involving noreturn and redeclarations.
[Bug c++/99974] attributes not propagated across function redeclarations at local scope
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99974 Andrew Pinski changed: What|Removed |Added See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=99843 --- Comment #3 from Andrew Pinski --- Related to PR 99843 where there is a friend function declaration instead of just a local scope declaration of the function. But I suspect they are all the same issue where the merging of the attributes is lost.
[Bug c++/99974] attributes not propagated across function redeclarations at local scope
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99974 --- Comment #2 from Martin Sebor --- 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); | ^~
[Bug c++/99974] attributes not propagated across function redeclarations at local scope
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99974 Martin Sebor changed: What|Removed |Added Keywords||diagnostic See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=99972 --- Comment #1 from Martin Sebor --- This never worked correctly so it's not a regression. Clang behaves as expected in both C and C++ modes and issues the following warnings: z.C:18:3: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result] fwur (); // -Wunused-result (good) ^~~~ z.C:25:3: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result] fwur (); // missing -Wunused-result (bug) ^~~~ 2 warnings generated.