1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 4 // RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 5 6 namespace std { struct type_info; } 7 8 namespace dr1902 { // dr1902: 3.7 9 struct A {}; 10 struct B { 11 B(A); 12 #if __cplusplus >= 201103L 13 // expected-note@-2 {{candidate}} 14 #endif 15 16 B() = delete; 17 #if __cplusplus < 201103L 18 // expected-error@-2 {{extension}} 19 #endif 20 21 B(const B&) // expected-note {{deleted here}} 22 #if __cplusplus >= 201103L 23 // expected-note@-2 {{candidate}} 24 #else 25 // expected-error@+2 {{extension}} 26 #endif 27 = delete; 28 29 operator A(); 30 }; 31 32 extern B b1; 33 B b2(b1); // expected-error {{call to deleted}} 34 35 #if __cplusplus >= 201103L 36 // This is ambiguous, even though calling the B(const B&) constructor would 37 // both directly and indirectly call a deleted function. 38 B b({}); // expected-error {{ambiguous}} 39 #endif 40 } 41 42 namespace dr1903 { 43 namespace A { 44 struct a {}; 45 int a; 46 namespace B { 47 int b; 48 } 49 using namespace B; 50 namespace { 51 int c; 52 } 53 namespace D { 54 int d; 55 } 56 using D::d; 57 } 58 namespace X { 59 using A::a; 60 using A::b; 61 using A::c; 62 using A::d; 63 struct a *p; 64 } 65 } 66 67 namespace dr1909 { // dr1909: yes 68 struct A { 69 template<typename T> struct A {}; // expected-error {{member 'A' has the same name as its class}} 70 }; 71 struct B { Bdr1909::B72 template<typename T> void B() {} // expected-error {{constructor cannot have a return type}} 73 }; 74 struct C { 75 template<typename T> static int C; // expected-error {{member 'C' has the same name as its class}} expected-error 0-1{{extension}} 76 }; 77 struct D { 78 template<typename T> using D = int; // expected-error {{member 'D' has the same name as its class}} expected-error 0-1{{extension}} 79 }; 80 } 81 82 namespace dr1940 { // dr1940: yes 83 #if __cplusplus >= 201103L 84 static union { 85 static_assert(true, ""); // ok 86 static_assert(false, ""); // expected-error {{static_assert failed}} 87 int not_empty; 88 }; 89 #endif 90 } 91 92 namespace dr1941 { // dr1941: 3.9 93 #if __cplusplus >= 201402L 94 template<typename X> 95 struct base { 96 template<typename T> 97 base(T a, T b, decltype(void(*T()), 0) = 0) { 98 while (a != b) (void)*a++; 99 } 100 101 template<typename T> 102 base(T a, X x, decltype(void(T(0) * 1), 0) = 0) { 103 for (T n = 0; n != a; ++n) (void)X(x); 104 } 105 }; 106 107 struct derived : base<int> { 108 using base::base; 109 }; 110 111 struct iter { 112 iter operator++(int); 113 int operator*(); 114 friend bool operator!=(iter, iter); 115 } it, end; 116 117 derived d1(it, end); 118 derived d2(42, 9); 119 #endif 120 } 121 122 namespace dr1947 { // dr1947: yes 123 #if __cplusplus >= 201402L 124 unsigned o = 0'01; // ok 125 unsigned b = 0b'01; // expected-error {{invalid digit 'b' in octal constant}} 126 unsigned x = 0x'01; // expected-error {{invalid suffix 'x'01' on integer constant}} 127 #endif 128 } 129 130 #if __cplusplus >= 201103L 131 // dr1948: yes 132 // FIXME: This diagnostic could be improved. 133 void *operator new(__SIZE_TYPE__) noexcept { return nullptr; } // expected-error{{exception specification in declaration does not match previous declaration}} 134 #endif 135 136 namespace dr1959 { // dr1959: 3.9 137 #if __cplusplus >= 201103L 138 struct b; 139 struct c; 140 struct a { 141 a() = default; 142 a(const a &) = delete; // expected-note {{deleted}} 143 a(const b &) = delete; // not inherited 144 a(c &&) = delete; // expected-note {{not viable}} 145 template<typename T> a(T) = delete; // expected-note {{would take its own class type by value}} 146 }; 147 148 struct b : a { // expected-note {{cannot bind}} expected-note {{deleted because}} 149 using a::a; // expected-note 2{{inherited here}} 150 }; 151 152 a x; 153 // FIXME: As a resolution to an open DR against P0136R0, we disallow 154 // use of inherited constructors to construct from a single argument 155 // where the base class is reference-related to the argument type. 156 b y = x; // expected-error {{no viable conversion}} 157 b z = z; // expected-error {{deleted}} 158 159 struct c : a { 160 using a::a; 161 c(const c &); 162 }; 163 // FIXME: As a resolution to an open DR against P0136R0, we disallow 164 // use of inherited constructors to construct from a single argument 165 // where the base class is reference-related to the argument type. 166 c q(static_cast<c&&>(q)); 167 #endif 168 } 169 170 namespace dr1966 { // dr1966: 11 171 #if __cplusplus >= 201103L 172 struct A { 173 enum E : int {1}; // expected-error {{expected identifier}} (not bit-field) 174 }; 175 auto *p1 = new enum E : int; // expected-error {{only permitted as a standalone declaration}} 176 auto *p2 = new enum F : int {}; // expected-error {{cannot be defined in a type specifier}} 177 auto *p3 = true ? new enum G : int {}; // expected-error {{forward reference}} expected-error {{incomplete}} expected-note {{declaration}} 178 auto h() -> enum E : int {}; // expected-error {{only permitted as a standalone declaration}} 179 180 enum X : enum Y : int {} {}; // expected-error {{cannot be defined in a type specifier}} 181 struct Q { 182 enum X : enum Y : int {} {}; // expected-error +{{}} 183 }; 184 #endif 185 } 186 187 namespace dr1968 { // dr1968: no 188 #if __cplusplus >= 201103L 189 // FIXME: According to DR1968, both of these should be considered 190 // non-constant. 191 static_assert(&typeid(int) == &typeid(int), ""); 192 193 constexpr const std::type_info *f() { return &typeid(int); } 194 static_assert(f() == f(), ""); 195 #endif 196 } 197 198 namespace dr1991 { // dr1991: 3.9 199 #if __cplusplus >= 201103L 200 struct A { 201 A(int, int) = delete; 202 }; 203 204 struct B : A { 205 using A::A; 206 B(int, int, int = 0); 207 }; 208 209 // FIXME: As a resolution to an open DR against P0136R1, we treat derived 210 // class constructors as better than base class constructors in the presence 211 // of ambiguity. 212 B b(0, 0); // ok, calls B constructor 213 #endif 214 } 215 216 // dr1994: dup 529 217