https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66671

            Bug ID: 66671
           Summary: Failure to create a new family of templates for
                    template alias
           Product: gcc
           Version: 5.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thiago at kde dot org
  Target Milestone: ---

Whenever you use:

template <typename T>
using Z = Y<T>;

The template Z is different from Y and should be encoded separately. This can
be seen in the example:

====
#include <iostream>

template <template <typename> class>
struct X {
  X() { std::cout << "1"; }
};

template <typename>
struct Y {};

template <typename T>
using Z = Y<T>;

template <>
struct X<Y> {
  X() { std::cout << "2"; }
};

int main() {
  X<Y> x1;
  X<Z> x2;
}
====
(from: http://cppquiz.org/quiz/giveup/117)

With GCC 5.1.1, the above prints "22", whereas it prints "21" with ICC 16,
Clang 3.7 and MSVC 2013. The explanation from the quiz site is given as:

> According to §14.5.7¶1 in the standard, a template alias declaration 
> resolve to a new family of types. The specialization cannot be used, 
> and the first template delcaration is used instead, printing 1.

Disassembly with -O2 -fno-inline shows that Clang and ICC both call different
template specialisations of template class X:

        leaq    16(%rsp), %rdi
        callq   _ZN1XI1YEC2Ev          ; X<Y>::X()
        leaq    8(%rsp), %rdi
        callq   _ZN1XI1ZEC2Ev          ; X<Z>::X()

PS: should X<Z> count as a local type or a global one?

Reply via email to