https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89309
Bug ID: 89309
Summary: bogus -Wattributes ‘copy’ attribute ignored on a
declaration of a different kind than referenced symbol
Product: gcc
Version: 9.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: ---
The copy attribute newly introduced in GCC 9 (see pr81824) doesn't handle C++
templates entirely correctly. The test case below shows that it successfully
copies the noreturn attribute from f<T> to g<T> but in the process it also
issues a spurious warning.
$ cat z.C && gcc -S -Wall z.C
template <class T> __attribute__ ((noreturn)) T f ();
template <class T>
__attribute__ ((copy (f<T>))) T g () // bogus -Wattributes
{
f<T>();
} // no -Wreturn-type (good)
template int g<int>();
z.C: In substitution of ‘template<class T> T g() [with T = int]’:
z.C:9:21: required from here
z.C:4:33: warning: ‘copy’ attribute ignored on a declaration of a different
kind than referenced symbol [-Wattributes]
4 | __attribute__ ((copy (f<T>))) T g () // bogus -Wattributes
| ^