2

Consider the following code:

template <template <int> class T>
struct B {
};

template <int N>
struct A {
    B<A> b;
};

This does not compile since A in B<A> b refers to the class A<N>, not the template. How can I get the template A from inside the body of A<N>?

  • +1 @T.C. Exactly, thanks! I can accept your comment as an answer if you post. โ€“  Jun 14 '14 at 03:37
  • 2
    @par This is a clang [bug](http://llvm.org/bugs/show_bug.cgi?id=9551), your code is valid. โ€“ Praetorian Jun 14 '14 at 04:27

1 Answers1

1

Simplest way to bypass this issue, I think:

template <int N>
struct A {
    B<::A> b;
};

Although it's actually a very interesting issue because it seems that B<A> should work. From ยง14.6.1 [temp.local]/p1 of N3936:

Like normal (non-template) classes, class templates have an injected-class-name (Clause 9). The injected-class-name can be used as a template-name or a type-name. When it is used with a template-argument-list, as a template-argument for a template template-parameter, or as the final identifier in the elaborated-type-specifier of a friend class template declaration, it refers to the class template itself. Otherwise, it is equivalent to the template-name followed by the template-parameters of the class template enclosed in <>.

So it seems like B<A> should be equivalent to B<::A>. GCC 4.8 accepts the code in the OP, though Clang 3.4 doesn't.

T.C.
  • 133,968
  • 17
  • 288
  • 421