Function template cannot hide class name?

This works in GCC and Comeau:

struct X {}; void X() {} 

This happens in Como:

 struct X {}; template< typename T > void X() {} 

This interrupts both:

 template< typename T > struct X {}; template< typename T > void X() {} 

The rule is defined in clause 3.3.7 / 2. Is the mismatch simply because the function template is not a function? I can not understand the behavior of GCC.

The class name (9.1) or enumeration name (7.2) can be hidden by the variable name, data member, function, or enumerator declared in the same scope. If the class or enumeration name and 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 counter name is visible.

+4
source share
1 answer

This is because spec says in 14.p5:

A class template must 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). In addition to the fact that a function template can be overloaded with either (non-template) functions with the same name or other functional templates with the same name (14.8.3), the name of the template declared in the namespace or in the class scope must be unique in this area.

+4
source

All Articles