blob: 8911328b4cd496feb756855510f77675b13d3458 [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -verify -std=c++11 %s
Richard Smith3e4c6c42011-05-05 21:57:07 +00002
3namespace RedeclAliasTypedef {
4 template<typename U> using T = int;
5 template<typename U> using T = int;
6 template<typename U> using T = T<U>;
7}
8
9namespace IllegalTypeIds {
10 template<typename U> using A = void(int n = 0); // expected-error {{default arguments can only be specified for parameters in a function declaration}}
11 template<typename U> using B = inline void(int n); // expected-error {{type name does not allow function specifier}}
12 template<typename U> using C = virtual void(int n); // expected-error {{type name does not allow function specifier}}
13 template<typename U> using D = explicit void(int n); // expected-error {{type name does not allow function specifier}}
14 template<typename U> using E = void(int n) throw(); // expected-error {{exception specifications are not allowed in type aliases}}
Richard Smithd37b3602012-02-10 11:05:11 +000015 template<typename U> using F = void(*)(int n) &&; // expected-error {{pointer to function type cannot have '&&' qualifier}}
Richard Smith3e4c6c42011-05-05 21:57:07 +000016 template<typename U> using G = __thread void(int n); // expected-error {{type name does not allow storage class to be specified}}
17
18 template<typename U> using H = void(int n); // ok
19 template<typename U> using I = void(int n) &&; // ok
20}
21
22namespace IllegalSyntax {
23 template<typename Z> using ::T = void(int n); // expected-error {{name defined in alias declaration must be an identifier}}
24 template<typename Z> using operator int = void(int n); // expected-error {{name defined in alias declaration must be an identifier}}
25 template<typename Z> using typename U = void; // expected-error {{name defined in alias declaration must be an identifier}}
26 template<typename Z> using typename ::V = void(int n); // expected-error {{name defined in alias declaration must be an identifier}}
27 template<typename Z> using typename ::operator bool = void(int n); // expected-error {{name defined in alias declaration must be an identifier}}
28}
29
30namespace VariableLengthArrays {
31 template<typename Z> using T = int[42]; // ok
32
33 int n = 32;
34 template<typename Z> using T = int[n]; // expected-error {{variable length array declaration not allowed at file scope}}
35
36 const int m = 42;
37 template<typename Z> using U = int[m]; // expected-note {{previous definition}}
38 template<typename Z> using U = int[42]; // ok
39 template<typename Z> using U = int; // expected-error {{type alias template redefinition with different types ('int' vs 'int [42]')}}
40}
41
42namespace RedeclFunc {
43 int f(int, char**);
44 template<typename Z> using T = int;
45 T<char> f(int, char **); // ok
46}
47
48namespace LookupFilter {
49 namespace N { template<typename U> using S = int; }
50 using namespace N;
51 template<typename U> using S = S<U>*; // ok
52}
53
54namespace InFunctions {
55 template<typename...T> struct S0 {
56 template<typename Z> using U = T*; // expected-error {{declaration type contains unexpanded parameter pack 'T'}}
57 U<char> u;
58 };
59
60 template<typename Z> using T1 = int;
61 template<typename Z> using T2 = int[-1]; // expected-error {{array size is negative}}
62 template<typename...T> struct S3 { // expected-note {{template parameter is declared here}}
63 template<typename Z> using T = int; // expected-error {{declaration of 'T' shadows template parameter}}
64 };
65 template<typename Z> using Z = Z;
66}
67
68namespace ClassNameRedecl {
69 class C0 {
70 // FIXME: this diagnostic is pretty poor
71 template<typename U> using C0 = int; // expected-error {{name defined in alias declaration must be an identifier}}
72 };
73 class C1 {
74 // FIXME: this diagnostic is pretty poor
75 template<typename U> using C1 = C1; // expected-error {{name defined in alias declaration must be an identifier}}
76 };
77 class C2 {
78 template<typename U> using C0 = C1; // ok
79 };
80 template<typename...T> class C3 {
81 template<typename U> using f = T; // expected-error {{declaration type contains unexpanded parameter pack 'T'}}
82 };
83 template<typename T> class C4 { // expected-note {{template parameter is declared here}}
84 template<typename U> using T = int; // expected-error {{declaration of 'T' shadows template parameter}}
85 };
86 class C5 {
87 class c; // expected-note {{previous definition}}
88 template<typename U> using c = int; // expected-error {{redefinition of 'c' as different kind of symbol}}
89 class d; // expected-note {{previous definition}}
90 template<typename U> using d = d; // expected-error {{redefinition of 'd' as different kind of symbol}}
91 };
92 class C6 {
93 class c { template<typename U> using C6 = int; }; // ok
94 };
95}
96
97class CtorDtorName {
98 template<typename T> using X = CtorDtorName;
99 X<int>(); // expected-error {{expected member name}}
100 ~X<int>(); // expected-error {{destructor cannot be declared using a type alias}}
101};
102
103namespace TagName {
104 template<typename Z> using S = struct { int n; }; // expected-error {{can not be defined}}
105 template<typename Z> using T = class { int n; }; // expected-error {{can not be defined}}
106 template<typename Z> using U = enum { a, b, c }; // expected-error {{can not be defined}}
107 template<typename Z> using V = struct V { int n; }; // expected-error {{redefinition of 'V' as different kind of symbol}} \
108 expected-error {{'TagName::V' can not be defined in a type alias template}} \
109 expected-note {{previous definition is here}}
110}
111
112namespace StdExample {
113 template<typename T, typename U> struct pair;
114
115 template<typename T> using handler_t = void (*)(T);
116 extern handler_t<int> ignore;
117 extern void (*ignore)(int);
118 // FIXME: we recover as if cell is an undeclared variable. the diagnostics are terrible!
119 template<typename T> using cell = pair<T*, cell<T>*>; // expected-error {{use of undeclared identifier 'cell'}} \
120 expected-error {{'T' does not refer to a value}} \
121 expected-note {{declared here}} \
122 expected-error {{expected ';' after alias declaration}}
123}
124
125namespace Access {
126 class C0 {
127 template<typename Z> using U = int; // expected-note {{declared private here}}
128 };
129 C0::U<int> v; // expected-error {{'U' is a private member}}
130 class C1 {
131 public:
132 template<typename Z> using U = int;
133 };
134 C1::U<int> w; // ok
135}
136
137namespace VoidArg {
138 template<typename Z> using V = void;
139 V<int> f(int); // ok
140 V<char> g(V<double>); // expected-error {{empty parameter list defined with a type alias of 'void' not allowed}}
141}
142
143namespace Curried {
144 template<typename T, typename U> struct S;
145 template<typename T> template<typename U> using SS = S<T, U>; // expected-error {{extraneous template parameter list in alias template declaration}}
146}