Reputation: 137800
This works in GCC and Comeau:
struct X {};
void X() {}
This breaks in Comeau:
struct X {};
template< typename T >
void X() {}
This breaks both:
template< typename T >
struct X {};
template< typename T >
void X() {}
The rule is defined by §3.3.7/2. Is the discrepancy simply because a function template is not a function? I can't make sense of GCC's behavior.
A class name (9.1) or enumeration name (7.2) can be hidden by the name of a variable, data member, function, or enumerator declared in the same scope. If a class or enumeration name and a variable, data member, function, or enumerator are declared in the same scope (in any order) with the same name, the class or enumeration name is hidden wherever the variable, data member, function, or enumerator name is visible.
Upvotes: 4
Views: 350
Reputation: 506925
That's because the spec says in 14.p5:
A class template shall not have the same name as any other template, class, function, variable, enumeration, enumerator, namespace, or type in the same scope (3.3), except as specified in (14.5.5). Except that a function template can be overloaded either by (non-template) functions with the same name or by other function templates with the same name (14.8.3), a template name declared in namespace scope or in class scope shall be unique in that scope.
Upvotes: 4