Explicit specialization in a domain without a namespace does not compile in GCC

The following code compiles in Clang, but not in GCC:

template<typename T> struct Widget { template<typename U> void foo(U) { } template<> void foo(int*) { } }; 

According to the C ++ standard ([temp.expl.spec], paragraph 2):

Explicit specialization can be declared in any field in which the corresponding primary pattern can be used.

Is this a bug in GCC, and if so, how can I find it in my bug tracker?

This is the output of GCC:

 prog.cc:13:14: error: explicit specialization in non-namespace scope 'struct Widget<T>' template<> ^ 

I am using GCC HEAD 8.0.1 with -std=c++2a .

+5
source share
1 answer

It must be a GCC bug. Full specialization should be allowed in any field, including in the definition of a class.

In accordance with CWG 727, the parameter [temp.expl.spec] has been changed from

(my emphasis)

Explicit specialization must be declared in a namespace encompassing a specialized pattern. An explicit specialization whose declarator identifier or class name is not qualified is declared in the nearest enclosing template namespace or, if the namespace is inline (10.3.1 [namespace.def]), any namespace from it including the namespace. Such an expression may also be a definition. If the declaration is not a definition, specialization may be defined later (10.3.1.2 [namespace.memdef]).

to

(my emphasis)

Explicit specialization can be declared in any field in which the corresponding primary template can be defined (10.3.1.2 [namespace.memdef], 12.2 [class.mem], 17.6.2 [temp.mem]).

GCC does not seem to be doing this.

+3
source

Source: https://habr.com/ru/post/1276291/


All Articles