Clang Project

clang_source_code/test/SemaTemplate/typename-specifier-3.cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3// PR4364
4template<class T> struct a { // expected-note {{here}}
5  T b() {
6    return typename T::x();
7  }
8};
9struct B {
10  typedef B x;
11};
12B c() {
13  a<B> x;
14  return x.b();
15}
16
17// Some extra tests for invalid cases
18template<class T> struct test2 { T b() { return typename T::a; } }; // expected-error{{expected '(' for function-style cast or type construction}}
19template<class T> struct test3 { T b() { return typename a; } }; // expected-error{{expected a qualified name after 'typename'}}
20template<class T> struct test4 { T b() { return typename ::a; } }; // expected-error{{refers to non-type member}} expected-error{{expected '(' for function-style cast or type construction}}
21
22// PR12884
23namespace PR12884_original {
24  template <typename T> struct A {
25    struct B {
26      template <typename U> struct X {};
27      typedef int arg;
28    };
29    struct C {
30      typedef B::X<typename B::arg> x; // expected-error {{missing 'typename'}}
31    };
32  };
33
34  template <> struct A<int>::B {
35    template <int N> struct X {};
36    static const int arg = 0;
37  };
38
39  A<int>::C::x a;
40}
41namespace PR12884_half_fixed {
42  template <typename T> struct A {
43    struct B {
44      template <typename U> struct X {};
45      typedef int arg;
46    };
47    struct C {
48      typedef typename B::X<typename B::arg> x; // expected-error {{use 'template'}} expected-error {{refers to non-type}}
49    };
50  };
51
52  template <> struct A<int>::B {
53    template <int N> struct X {};
54    static const int arg = 0; // expected-note {{here}}
55  };
56
57  A<int>::C::x a; // expected-note {{here}}
58}
59namespace PR12884_fixed {
60  template <typename T> struct A {
61    struct B {
62      template <typename U> struct X {};
63      typedef int arg;
64    };
65    struct C {
66      typedef typename B::template X<B::arg> x;
67    };
68  };
69
70  template <> struct A<int>::B {
71    template <int N> struct X {};
72    static const int arg = 0;
73  };
74
75  A<int>::C::x a; // ok
76}
77