1762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// RUN: %clang_cc1 -verify -std=c++11 %s
23e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
33e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithnamespace RedeclAliasTypedef {
43e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename U> using T = int;
53e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename U> using T = int;
63e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename U> using T = T<U>;
73e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith}
83e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
93e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithnamespace IllegalTypeIds {
103e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename U> using A = void(int n = 0); // expected-error {{default arguments can only be specified for parameters in a function declaration}}
113e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename U> using B = inline void(int n); // expected-error {{type name does not allow function specifier}}
123e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename U> using C = virtual void(int n); // expected-error {{type name does not allow function specifier}}
133e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename U> using D = explicit void(int n); // expected-error {{type name does not allow function specifier}}
143e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename U> using E = void(int n) throw(); // expected-error {{exception specifications are not allowed in type aliases}}
15d37b360bf9f954af119c9805fdc79ab9d30e06c6Richard Smith  template<typename U> using F = void(*)(int n) &&; // expected-error {{pointer to function type cannot have '&&' qualifier}}
163e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename U> using G = __thread void(int n); // expected-error {{type name does not allow storage class to be specified}}
1769730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith  template<typename U> using H = constexpr int; // expected-error {{type name does not allow constexpr specifier}}
183e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
1969730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith  template<typename U> using Y = void(int n); // ok
2069730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith  template<typename U> using Z = void(int n) &&; // ok
213e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith}
223e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
233e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithnamespace IllegalSyntax {
243e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using ::T = void(int n); // expected-error {{name defined in alias declaration must be an identifier}}
253e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using operator int = void(int n); // expected-error {{name defined in alias declaration must be an identifier}}
263e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using typename U = void; // expected-error {{name defined in alias declaration must be an identifier}}
273e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using typename ::V = void(int n); // expected-error {{name defined in alias declaration must be an identifier}}
283e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using typename ::operator bool = void(int n); // expected-error {{name defined in alias declaration must be an identifier}}
293e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith}
303e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
313e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithnamespace VariableLengthArrays {
323e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using T = int[42]; // ok
333e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
343e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  int n = 32;
353e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using T = int[n]; // expected-error {{variable length array declaration not allowed at file scope}}
363e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
373e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  const int m = 42;
383e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using U = int[m]; // expected-note {{previous definition}}
393e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using U = int[42]; // ok
403e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using U = int; // expected-error {{type alias template redefinition with different types ('int' vs 'int [42]')}}
413e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith}
423e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
433e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithnamespace RedeclFunc {
443e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  int f(int, char**);
453e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using T = int;
463e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  T<char> f(int, char **); // ok
473e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith}
483e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
493e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithnamespace LookupFilter {
503e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  namespace N { template<typename U> using S = int; }
513e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  using namespace N;
523e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename U> using S = S<U>*; // ok
533e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith}
543e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
553e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithnamespace InFunctions {
563e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename...T> struct S0 {
573e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    template<typename Z> using U = T*; // expected-error {{declaration type contains unexpanded parameter pack 'T'}}
583e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    U<char> u;
593e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  };
603e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
613e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using T1 = int;
623e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using T2 = int[-1]; // expected-error {{array size is negative}}
633e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename...T> struct S3 { // expected-note {{template parameter is declared here}}
643e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    template<typename Z> using T = int; // expected-error {{declaration of 'T' shadows template parameter}}
653e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  };
663e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using Z = Z;
673e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith}
683e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
693e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithnamespace ClassNameRedecl {
703e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  class C0 {
713e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // FIXME: this diagnostic is pretty poor
723e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    template<typename U> using C0 = int; // expected-error {{name defined in alias declaration must be an identifier}}
733e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  };
743e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  class C1 {
753e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // FIXME: this diagnostic is pretty poor
763e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    template<typename U> using C1 = C1; // expected-error {{name defined in alias declaration must be an identifier}}
773e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  };
783e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  class C2 {
793e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    template<typename U> using C0 = C1; // ok
803e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  };
813e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename...T> class C3 {
823e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    template<typename U> using f = T; // expected-error {{declaration type contains unexpanded parameter pack 'T'}}
833e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  };
843e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename T> class C4 { // expected-note {{template parameter is declared here}}
853e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    template<typename U> using T = int; // expected-error {{declaration of 'T' shadows template parameter}}
863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  };
873e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  class C5 {
883e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    class c; // expected-note {{previous definition}}
893e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    template<typename U> using c = int; // expected-error {{redefinition of 'c' as different kind of symbol}}
903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    class d; // expected-note {{previous definition}}
913e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    template<typename U> using d = d; // expected-error {{redefinition of 'd' as different kind of symbol}}
923e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  };
933e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  class C6 {
943e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    class c { template<typename U> using C6 = int; }; // ok
953e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  };
963e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith}
973e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
983e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithclass CtorDtorName {
993e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename T> using X = CtorDtorName;
1003e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  X<int>(); // expected-error {{expected member name}}
1013e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  ~X<int>(); // expected-error {{destructor cannot be declared using a type alias}}
1023e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith};
1033e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
1043e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithnamespace TagName {
1053e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using S = struct { int n; }; // expected-error {{can not be defined}}
1063e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using T = class { int n; }; // expected-error {{can not be defined}}
1073e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using U = enum { a, b, c }; // expected-error {{can not be defined}}
1083e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using V = struct V { int n; }; // expected-error {{redefinition of 'V' as different kind of symbol}} \
1093e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                                                         expected-error {{'TagName::V' can not be defined in a type alias template}} \
1103e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                                                         expected-note {{previous definition is here}}
1113e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith}
1123e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
1133e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithnamespace StdExample {
1143e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename T, typename U> struct pair;
1153e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
1163e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename T> using handler_t = void (*)(T);
1173e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  extern handler_t<int> ignore;
1183e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  extern void (*ignore)(int);
1193e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  // FIXME: we recover as if cell is an undeclared variable. the diagnostics are terrible!
1203e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename T> using cell = pair<T*, cell<T>*>; // expected-error {{use of undeclared identifier 'cell'}} \
1213e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                                                           expected-error {{'T' does not refer to a value}} \
1223e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                                                           expected-note {{declared here}} \
1233e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                                                           expected-error {{expected ';' after alias declaration}}
1243e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith}
1253e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
1263e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithnamespace Access {
1273e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  class C0 {
1283e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    template<typename Z> using U = int; // expected-note {{declared private here}}
1293e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  };
1303e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  C0::U<int> v; // expected-error {{'U' is a private member}}
1313e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  class C1 {
1323e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  public:
1333e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    template<typename Z> using U = int;
1343e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  };
1353e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  C1::U<int> w; // ok
1363e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith}
1373e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
1383e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithnamespace VoidArg {
1393e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename Z> using V = void;
1403e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  V<int> f(int); // ok
1413e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  V<char> g(V<double>); // expected-error {{empty parameter list defined with a type alias of 'void' not allowed}}
1423e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith}
1433e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
1443e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithnamespace Curried {
1453e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename T, typename U> struct S;
1463e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  template<typename T> template<typename U> using SS = S<T, U>; // expected-error {{extraneous template parameter list in alias template declaration}}
1473e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith}
148