https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81762
Bug ID: 81762
Summary: errors defining attribute target overloads of the same
function template
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: ---
G++ accepts definitions of distinct overloads of the same function that differ
only in their target attribute specifier but rejects definitions of equivalent
"overloads" of function templates, or "overloads" of the same explicit
specializations of a function template.
In the test case below, I expect all the definitions to be accepted as distinct
but the template ones are rejected with errors that suggest an incomplete
integration of the attribute target feature into the C++ front end.
$ cat a.c && gcc -Wall -Wextra -xc++ a.c && ./a.out
#define A "arch=corei7"
void __attribute__ ((target ("default")))
foo (int) { }
void __attribute__ ((target (A)))
foo (int) { /* okay, different foo */ }
template <class T>
void bar (T);
template <>
void __attribute__ ((target ("default")))
bar<int>(int) { }
template <>
void __attribute__ ((target (A)))
bar<int>(int) { /* rejected (bug?) */ }
template <class T>
void __attribute__ ((target ("default")))
baz (T) { }
template <class T>
void __attribute__ ((target (A)))
baz (T) { /* rejected (bug?) */ }
a.c:19:1: error: redefinition of ‘void bar(T) [with T = int]’
bar<int>(int) { /* rejected (bug?) */ }
^~~~~~~~
a.c:15:1: note: ‘void bar(T) [with T = int]’ previously declared here
bar<int>(int) { }
^~~~~~~~
a.c:28:1: error: ambiguating new declaration ‘template<class T> void baz(T)’
baz (T) { /* rejected (bug?) */ }
^~~
a.c:24:1: note: old declaration ‘template<class T> void baz(T)’
baz (T) { }
^~~