p2-0x.cpp revision 69730c115c2d0fec2f20609d905d920a5a41b29b
1// RUN: %clang_cc1 -verify -std=c++11 %s
2
3namespace RedeclAliasTypedef {
4  typedef int T;
5  using T = int;
6  using T = int;
7  typedef T T;
8  using T = T;
9  typedef int T;
10}
11
12namespace IllegalTypeIds {
13  using A = void(int n = 0); // expected-error {{default arguments can only be specified for parameters in a function declaration}}
14  using B = inline void(int n); // expected-error {{type name does not allow function specifier}}
15  using C = virtual void(int n); // expected-error {{type name does not allow function specifier}}
16  using D = explicit void(int n); // expected-error {{type name does not allow function specifier}}
17  using E = void(int n) throw(); // expected-error {{exception specifications are not allowed in type aliases}}
18  using F = void(*)(int n) &&; // expected-error {{pointer to function type cannot have '&&' qualifier}}
19  using G = __thread void(int n); // expected-error {{type name does not allow storage class to be specified}}
20  using H = constexpr int; // expected-error {{type name does not allow constexpr specifier}}
21
22  using Y = void(int n); // ok
23  using Z = void(int n) &&; // ok
24}
25
26namespace IllegalSyntax {
27  using ::T = void(int n); // expected-error {{name defined in alias declaration must be an identifier}}
28  using operator int = void(int n); // expected-error {{name defined in alias declaration must be an identifier}}
29  using typename U = void; // expected-error {{name defined in alias declaration must be an identifier}}
30  using typename ::V = void(int n); // expected-error {{name defined in alias declaration must be an identifier}}
31  using typename ::operator bool = void(int n); // expected-error {{name defined in alias declaration must be an identifier}}
32}
33
34namespace VariableLengthArrays {
35  using T = int[42]; // ok
36
37  int n = 32;
38  using T = int[n]; // expected-error {{variable length array declaration not allowed at file scope}}
39
40  const int m = 42;
41  using U = int[m]; // expected-note {{previous definition}}
42  using U = int[42]; // ok
43  using U = int; // expected-error {{type alias redefinition with different types ('int' vs 'int [42]')}}
44
45  void f() {
46    int n = 42;
47    goto foo; // expected-error {{goto into protected scope}}
48    using T = int[n]; // expected-note {{bypasses initialization of VLA type alias}}
49  foo: ;
50  }
51}
52
53namespace RedeclFunc {
54  int f(int, char**);
55  using T = int;
56  T f(int, char **); // ok
57}
58
59namespace LookupFilter {
60  namespace N { struct S; }
61  using namespace N;
62  using S = S*; // ok
63}
64
65namespace InFunctions {
66  template<typename...T> void f0() {
67    using U = T*; // expected-error {{declaration type contains unexpanded parameter pack 'T'}}
68    U u;
69  }
70  template void f0<int, char>();
71
72  void f1() {
73    using T = int;
74  }
75  void f2() {
76    using T = int[-1]; // expected-error {{array size is negative}}
77  }
78
79  template<typename...T> void f3() { // expected-note {{template parameter is declared here}}
80    using T = int; // expected-error {{declaration of 'T' shadows template parameter}}
81  }
82}
83
84namespace ClassNameRedecl {
85  class C0 {
86    // FIXME: this diagnostic is pretty poor
87    using C0 = int; // expected-error {{name defined in alias declaration must be an identifier}}
88  };
89  class C1 {
90    // FIXME: this diagnostic is pretty poor
91    using C1 = C1; // expected-error {{name defined in alias declaration must be an identifier}}
92  };
93  class C2 {
94    using C0 = C1; // ok
95  };
96  template<typename...T> class C3 {
97    using f = T; // expected-error {{declaration type contains unexpanded parameter pack 'T'}}
98  };
99  template<typename T> class C4 { // expected-note {{template parameter is declared here}}
100    using T = int; // expected-error {{declaration of 'T' shadows template parameter}}
101  };
102  class C5 {
103    class c; // expected-note {{previous definition}}
104    using c = int; // expected-error {{typedef redefinition with different types}}
105    class d;
106    using d = d; // ok
107  };
108  class C6 {
109    class c { using C6 = int; }; // ok
110  };
111}
112
113class CtorDtorName {
114  using X = CtorDtorName;
115  X(); // expected-error {{expected member name}}
116  ~X(); // expected-error {{destructor cannot be declared using a type alias}}
117};
118
119namespace TagName {
120  using S = struct { int n; };
121  using T = class { int n; };
122  using U = enum { a, b, c };
123  using V = struct V { int n; };
124}
125
126namespace CWG1044 {
127  // FIXME: this diagnostic isn't ideal. one diagnostic is enough.
128  using T = T; // expected-error {{type name requires a specifier}} \
129                  expected-error {{expected ';' after alias declaration}}
130}
131
132namespace StdExample {
133  template<typename T, typename U> struct pair;
134
135  using handler_t = void (*)(int);
136  extern handler_t ignore;
137  extern void (*ignore)(int);
138  // FIXME: we know we're parsing a type here; don't recover as if we were
139  // using operator*.
140  using cell = pair<void*, cell*>; // expected-error {{use of undeclared identifier 'cell'}} \
141                                      expected-error {{expected expression}}
142}
143
144namespace Access {
145  class C0 {
146    using U = int; // expected-note {{declared private here}}
147  };
148  C0::U v; // expected-error {{'U' is a private member}}
149  class C1 {
150  public:
151    using U = int;
152  };
153  C1::U w; // ok
154}
155
156namespace VoidArg {
157  using V = void;
158  V f(int); // ok
159  V g(V); // expected-error {{empty parameter list defined with a type alias of 'void' not allowed}}
160}
161