p2-0x.cpp revision 651f13cea278ec967336033dd032faef0e9fc2ec
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 using T = T; // expected-error {{unknown type name 'T'}} 128} 129 130namespace StdExample { 131 template<typename T, typename U> struct pair; 132 133 using handler_t = void (*)(int); 134 extern handler_t ignore; 135 extern void (*ignore)(int); 136 // FIXME: we know we're parsing a type here; don't recover as if we were 137 // using operator*. 138 using cell = pair<void*, cell*>; // expected-error {{use of undeclared identifier 'cell'}} \ 139 expected-error {{expected expression}} 140} 141 142namespace Access { 143 class C0 { 144 using U = int; // expected-note {{declared private here}} 145 }; 146 C0::U v; // expected-error {{'U' is a private member}} 147 class C1 { 148 public: 149 using U = int; 150 }; 151 C1::U w; // ok 152} 153 154namespace VoidArg { 155 using V = void; 156 V f(int); // ok 157 V g(V); // ok (DR577) 158} 159