1 // RUN: %clang_cc1 -verify -std=c++11 %s 2 3 namespace 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 12 namespace 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 26 namespace 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 34 namespace 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 {{cannot jump}} 48 using T = int[n]; // expected-note {{bypasses initialization of VLA type alias}} 49 foo: ; 50 } 51 } 52 53 namespace RedeclFunc { 54 int f(int, char**); 55 using T = int; 56 T f(int, char **); // ok 57 } 58 59 namespace LookupFilter { 60 namespace N { struct S; } 61 using namespace N; 62 using S = S*; // ok 63 } 64 65 namespace 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 84 namespace ClassNameRedecl { 85 class C0 { 86 using C0 = int; // expected-error {{member 'C0' has the same name as its class}} 87 }; 88 class C1 { 89 using C1 = C1; // expected-error {{member 'C1' has the same name as its class}} 90 }; 91 class C2 { 92 using C0 = C1; // ok 93 }; 94 template<typename...T> class C3 { 95 using f = T; // expected-error {{declaration type contains unexpanded parameter pack 'T'}} 96 }; 97 template<typename T> class C4 { // expected-note {{template parameter is declared here}} 98 using T = int; // expected-error {{declaration of 'T' shadows template parameter}} 99 }; 100 class C5 { 101 class c; // expected-note {{previous definition}} 102 using c = int; // expected-error {{typedef redefinition with different types}} 103 class d; 104 using d = d; // ok 105 }; 106 class C6 { 107 class c { using C6 = int; }; // ok 108 }; 109 } 110 111 class CtorDtorName { 112 using X = CtorDtorName; 113 X(); // expected-error {{expected member name}} 114 ~X(); // expected-error {{destructor cannot be declared using a type alias}} 115 }; 116 117 namespace TagName { 118 using S = struct { int n; }; 119 using T = class { int n; }; 120 using U = enum { a, b, c }; 121 using V = struct V { int n; }; 122 } 123 124 namespace CWG1044 { 125 using T = T; // expected-error {{unknown type name 'T'}} 126 } 127 128 namespace StdExample { 129 template<typename T, typename U> struct pair; 130 131 using handler_t = void (*)(int); 132 extern handler_t ignore; 133 extern void (*ignore)(int); 134 // FIXME: we know we're parsing a type here; don't recover as if we were 135 // using operator*. 136 using cell = pair<void*, cell*>; // expected-error {{use of undeclared identifier 'cell'}} \ 137 expected-error {{expected expression}} 138 } 139 140 namespace Access { 141 class C0 { 142 using U = int; // expected-note {{declared private here}} 143 }; 144 C0::U v; // expected-error {{'U' is a private member}} 145 class C1 { 146 public: 147 using U = int; 148 }; 149 C1::U w; // ok 150 } 151 152 namespace VoidArg { 153 using V = void; 154 V f(int); // ok 155 V g(V); // ok (DR577) 156 } 157