https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99587
Bug ID: 99587
Summary: warning: ‘retain’ attribute ignored while
__has_attribute(retain) is true
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: i at maskray dot me
Target Milestone: ---
If configure-time ld does not support SHF_GNU_RETAIN, __has_attribute(retain)
may be true while using it will cause a warning.
% cat x.c
#if defined(__has_attribute) && __has_attribute(retain)
__attribute__((used, retain)) int a;
#endif
% ~/Dev/gcc/out/release/gcc/xgcc -B ~/Dev/gcc/out/release/gcc -c x.c
x.c:1:1: warning: ‘retain’ attribute ignored [-Wattributes]
1 | __attribute__((used, retain)) int a;
| ^~~~~~~~~~~~~
% ~/Dev/gcc/out/release/gcc/xgcc --version
xgcc (GCC) 11.0.1 20210313 (experimental)
...
__has_attribute(retain) should return 0 in this case.