| 1 |
// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors |
| 2 |
// RUN: %clang_cc1 -std=c++11 %s -verify=expected,since-cxx11,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors |
| 3 |
// RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx11,since-cxx14,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors |
| 4 |
// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors |
| 5 |
// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors |
| 6 |
// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors |
| 7 |
// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors |
| 8 |
|
| 9 |
// FIXME: diagnostic above is emitted only on Windows platforms |
| 10 |
// PR13819 -- __SIZE_TYPE__ is incompatible. |
| 11 |
typedef __SIZE_TYPE__ size_t; |
| 12 |
// cxx98-error@-1 0-1 {{'long long' is a C++11 extension}} |
| 13 |
|
| 14 |
#if __cplusplus == 199711L |
| 15 |
#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__) |
| 16 |
// cxx98-error@-1 {{variadic macros are a C99 feature}} |
| 17 |
#endif |
| 18 |
|
| 19 |
#if __cplusplus == 199711L |
| 20 |
#define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x)) |
| 21 |
#else |
| 22 |
#define __enable_constant_folding |
| 23 |
#endif |
| 24 |
|
| 25 |
namespace cwg200 { // cwg200: dup 214 |
| 26 |
template <class T> T f(int); |
| 27 |
template <class T, class U> T f(U) = delete; |
| 28 |
// cxx98-error@-1 {{deleted function definitions are a C++11 extension}} |
| 29 |
|
| 30 |
void g() { |
| 31 |
f<int>(1); |
| 32 |
} |
| 33 |
} // namespace cwg200 |
| 34 |
|
| 35 |
// cwg201 is in cwg201.cpp |
| 36 |
|
| 37 |
namespace cwg202 { // cwg202: 3.1 |
| 38 |
template<typename T> T f(); |
| 39 |
template<int (*g)()> struct X { |
| 40 |
static_assert(__enable_constant_folding(g == &f<int>), ""); |
| 41 |
}; |
| 42 |
template struct X<f>; |
| 43 |
} // namespace cwg202 |
| 44 |
|
| 45 |
namespace cwg203 { // cwg203: 3.0 |
| 46 |
namespace ex1 { |
| 47 |
struct B { |
| 48 |
int i; |
| 49 |
}; |
| 50 |
struct D1 : B {}; |
| 51 |
struct D2 : B {}; |
| 52 |
|
| 53 |
int(D1::*pmD1) = &D2::i; |
| 54 |
} // namespace ex1 |
| 55 |
|
| 56 |
#if __cplusplus >= 202002L |
| 57 |
namespace ex2 { |
| 58 |
struct A { |
| 59 |
int i; |
| 60 |
virtual void f() = 0; // #cwg203-ex2-A-f |
| 61 |
}; |
| 62 |
|
| 63 |
struct B : A { |
| 64 |
int j; |
| 65 |
constexpr B() : j(5) {} |
| 66 |
virtual void f(); |
| 67 |
}; |
| 68 |
|
| 69 |
struct C : B { |
| 70 |
constexpr C() { j = 10; } |
| 71 |
}; |
| 72 |
|
| 73 |
template <class T> |
| 74 |
constexpr int DefaultValue(int(T::*m)) { |
| 75 |
return T().*m; |
| 76 |
// since-cxx20-error@-1 {{allocating an object of abstract class type 'cwg203::ex2::A'}} |
| 77 |
// since-cxx20-note@#cwg203-ex2-a {{in instantiation of function template specialization 'cwg203::ex2::DefaultValue<cwg203::ex2::A>' requested here}} |
| 78 |
// since-cxx20-note@#cwg203-ex2-A-f {{unimplemented pure virtual method 'f' in 'A'}} |
| 79 |
} // #cwg203-ex2-DefaultValue |
| 80 |
|
| 81 |
int a = DefaultValue(&B::i); // #cwg203-ex2-a |
| 82 |
static_assert(DefaultValue(&C::j) == 5, ""); |
| 83 |
} // namespace ex2 |
| 84 |
#endif |
| 85 |
|
| 86 |
namespace ex3 { |
| 87 |
class Base { |
| 88 |
public: |
| 89 |
int func() const; |
| 90 |
}; |
| 91 |
|
| 92 |
class Derived : public Base {}; |
| 93 |
|
| 94 |
template <class T> class Templ { // #cwg203-ex3-Templ |
| 95 |
public: |
| 96 |
template <class S> Templ(S (T::*ptmf)() const); // #cwg203-ex3-Templ-ctor |
| 97 |
}; |
| 98 |
|
| 99 |
void foo() { Templ<Derived> x(&Derived::func); } |
| 100 |
// expected-error@-1 {{no matching constructor for initialization of 'Templ<Derived>'}} |
| 101 |
// expected-note@#cwg203-ex3-Templ {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int (Derived::*)() const' (aka 'int (cwg203::ex3::Base::*)() const') to 'const Templ<cwg203::ex3::Derived>' for 1st argument}} |
| 102 |
// since-cxx11-note@#cwg203-ex3-Templ {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int (Derived::*)() const' (aka 'int (cwg203::ex3::Base::*)() const') to 'Templ<cwg203::ex3::Derived>' for 1st argument}} |
| 103 |
// expected-note@#cwg203-ex3-Templ-ctor {{candidate template ignored: could not match 'cwg203::ex3::Derived' against 'cwg203::ex3::Base'}} |
| 104 |
} // namespace ex3 |
| 105 |
|
| 106 |
namespace ex4 { |
| 107 |
struct Very_base { |
| 108 |
int a; |
| 109 |
}; |
| 110 |
struct Base1 : Very_base {}; |
| 111 |
struct Base2 : Very_base {}; |
| 112 |
struct Derived : Base1, Base2 { |
| 113 |
}; |
| 114 |
|
| 115 |
int f() { |
| 116 |
Derived d; |
| 117 |
// FIXME: in the diagnostic below, Very_base is fully qualified, but Derived is not |
| 118 |
int Derived::*a_ptr = &Derived::Base1::a; |
| 119 |
/* expected-error@-1 |
| 120 |
{{ambiguous conversion from pointer to member of base class 'cwg203::ex4::Very_base' to pointer to member of derived class 'Derived': |
| 121 |
struct cwg203::ex4::Derived -> Base1 -> Very_base |
| 122 |
struct cwg203::ex4::Derived -> Base2 -> Very_base}}*/ |
| 123 |
} |
| 124 |
} // namespace ex4 |
| 125 |
|
| 126 |
namespace ex5 { |
| 127 |
struct Base { |
| 128 |
int a; |
| 129 |
}; |
| 130 |
struct Derived : Base { |
| 131 |
int b; |
| 132 |
}; |
| 133 |
|
| 134 |
template <typename Class, typename Member_type, Member_type Base::*ptr> |
| 135 |
Member_type get(Class &c) { |
| 136 |
return c.*ptr; |
| 137 |
} |
| 138 |
|
| 139 |
void call(int (*f)(Derived &)); // #cwg203-ex5-call |
| 140 |
|
| 141 |
int f() { |
| 142 |
// ill-formed, contrary to Core issue filing: |
| 143 |
// `&Derived::b` yields `int Derived::*`, which can't initialize NTTP of type `int Base::*`, |
| 144 |
// because (implicit) pointer-to-member conversion doesn't upcast. |
| 145 |
call(&get<Derived, int, &Derived::b>); |
| 146 |
// expected-error@-1 {{no matching function for call to 'call'}} |
| 147 |
// expected-note@#cwg203-ex5-call {{candidate function not viable: no overload of 'get' matching 'int (*)(Derived &)' for 1st argument}} |
| 148 |
|
| 149 |
// well-formed, contrary to Core issue filing: |
| 150 |
// `&Derived::a` yields `int Base::*`, |
| 151 |
// which can initialize NTTP of type `int Base::*`. |
| 152 |
call(&get<Derived, int, &Derived::a>); |
| 153 |
|
| 154 |
call(&get<Base, int, &Derived::a>); |
| 155 |
// expected-error@-1 {{no matching function for call to 'call'}} |
| 156 |
// expected-note@#cwg203-ex5-call {{candidate function not viable: no overload of 'get' matching 'int (*)(Derived &)' for 1st argument}} |
| 157 |
} |
| 158 |
} // namespace ex5 |
| 159 |
|
| 160 |
namespace ex6 { |
| 161 |
struct Base { |
| 162 |
int a; |
| 163 |
}; |
| 164 |
struct Derived : private Base { // #cwg203-ex6-Derived |
| 165 |
public: |
| 166 |
using Base::a; // make `a` accessible |
| 167 |
}; |
| 168 |
|
| 169 |
int f() { |
| 170 |
Derived d; |
| 171 |
int b = d.a; |
| 172 |
// FIXME: in the diagnostic below, Base is fully qualified, but Derived is not |
| 173 |
int Derived::*ptr = &Derived::a; |
| 174 |
// expected-error@-1 {{cannot cast private base class 'cwg203::ex6::Base' to 'Derived'}} |
| 175 |
// expected-note@#cwg203-ex6-Derived {{declared private here}} |
| 176 |
} |
| 177 |
} // namespace ex6 |
| 178 |
} // namespace cwg203 |
| 179 |
|
| 180 |
// cwg204: sup 820 |
| 181 |
|
| 182 |
namespace cwg206 { // cwg206: 2.7 |
| 183 |
struct S; // #cwg206-S |
| 184 |
template<typename T> struct Q { S s; }; |
| 185 |
// expected-error@-1 {{field has incomplete type 'S'}} |
| 186 |
// expected-note@#cwg206-S {{forward declaration of 'cwg206::S'}} |
| 187 |
template<typename T> void f() { S s; } |
| 188 |
// expected-error@-1 {{variable has incomplete type 'S'}} |
| 189 |
// expected-note@#cwg206-S {{forward declaration of 'cwg206::S'}} |
| 190 |
} // namespace cwg206 |
| 191 |
|
| 192 |
namespace cwg207 { // cwg207: 2.7 |
| 193 |
class A { |
| 194 |
protected: |
| 195 |
static void f() {} |
| 196 |
}; |
| 197 |
class B : A { |
| 198 |
public: |
| 199 |
using A::f; |
| 200 |
void g() { |
| 201 |
A::f(); |
| 202 |
f(); |
| 203 |
} |
| 204 |
}; |
| 205 |
} // namespace cwg207 |
| 206 |
|
| 207 |
// cwg208 FIXME: write codegen test |
| 208 |
|
| 209 |
namespace cwg209 { // cwg209: 3.2 |
| 210 |
class A { |
| 211 |
void f(); // #cwg209-A-f |
| 212 |
}; |
| 213 |
class B { |
| 214 |
friend void A::f(); |
| 215 |
// expected-error@-1 {{friend function 'f' is a private member of 'cwg209::A'}} |
| 216 |
// expected-note@#cwg209-A-f {{implicitly declared private here}} |
| 217 |
}; |
| 218 |
} // namespace cwg209 |
| 219 |
|
| 220 |
// cwg210 is in cwg210.cpp |
| 221 |
|
| 222 |
namespace cwg211 { // cwg211: 2.7 |
| 223 |
struct A { |
| 224 |
A() try { |
| 225 |
throw 0; |
| 226 |
} catch (...) { |
| 227 |
return; |
| 228 |
// expected-error@-1 {{return in the catch of a function try block of a constructor is illegal}} |
| 229 |
} |
| 230 |
}; |
| 231 |
} // namespace cwg211 |
| 232 |
|
| 233 |
namespace cwg212 { // cwg212: 2.7 |
| 234 |
template<typename T> struct Base; |
| 235 |
template<typename T> struct Derived; |
| 236 |
|
| 237 |
int *overload(void*); |
| 238 |
float *overload(Base<int>*); |
| 239 |
double *overload(Base<long>*); |
| 240 |
|
| 241 |
void f(Derived<int> *p) { |
| 242 |
// OK, calls void* overload. |
| 243 |
int *a = overload(p); |
| 244 |
|
| 245 |
Base<int> *q = p; |
| 246 |
// expected-error@-1 {{cannot initialize a variable of type 'Base<int> *' with an lvalue of type 'Derived<int> *'}} |
| 247 |
} |
| 248 |
|
| 249 |
template<typename T> struct Base {}; |
| 250 |
template<typename T> struct Derived : Base<T> {}; |
| 251 |
|
| 252 |
void g(Derived<long> *p) { |
| 253 |
// OK, instantiates and calls Base<long>* overlod. |
| 254 |
double *b = overload(p); |
| 255 |
(void)b; |
| 256 |
} |
| 257 |
|
| 258 |
void h(Derived<float> *p) { |
| 259 |
// OK, instantiates and converts. |
| 260 |
Base<float> *q = p; |
| 261 |
(void)q; |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
namespace cwg213 { // cwg213: 2.7 |
| 266 |
template <class T> struct A : T { |
| 267 |
void h(T t) { |
| 268 |
char &r1 = f(t); |
| 269 |
int &r2 = g(t); |
| 270 |
// expected-error@-1 {{explicit qualification required to use member 'g' from dependent base class}} |
| 271 |
// expected-note@#cwg213-instantiation {{in instantiation of member function 'cwg213::A<cwg213::B>::h' requested here}} |
| 272 |
// expected-note@#cwg213-B-g {{member is declared here}} |
| 273 |
} |
| 274 |
}; |
| 275 |
struct B { |
| 276 |
int &f(B); |
| 277 |
int &g(B); // #cwg213-B-g |
| 278 |
}; |
| 279 |
char &f(B); |
| 280 |
|
| 281 |
template void A<B>::h(B); // #cwg213-instantiation |
| 282 |
} // namespace cwg213 |
| 283 |
|
| 284 |
namespace cwg214 { // cwg214: 2.7 |
| 285 |
template<typename T, typename U> T checked_cast(U from) { U::error; } |
| 286 |
template<typename T, typename U> T checked_cast(U *from); |
| 287 |
class C {}; |
| 288 |
void foo(int *arg) { checked_cast<const C *>(arg); } |
| 289 |
|
| 290 |
template<typename T> T f(int); |
| 291 |
template<typename T, typename U> T f(U) { T::error; } |
| 292 |
void g() { |
| 293 |
f<int>(1); |
| 294 |
} |
| 295 |
} // namespace cwg214 |
| 296 |
|
| 297 |
namespace cwg215 { // cwg215: 2.9 |
| 298 |
template<typename T> class X { |
| 299 |
friend void T::foo(); |
| 300 |
int n; |
| 301 |
}; |
| 302 |
struct Y { |
| 303 |
void foo() { (void)+X<Y>().n; } |
| 304 |
}; |
| 305 |
} // namespace cwg215 |
| 306 |
|
| 307 |
namespace cwg216 { // cwg216: no |
| 308 |
// FIXME: Should reject this: 'f' has linkage but its type does not, |
| 309 |
// and 'f' is odr-used but not defined in this TU. |
| 310 |
typedef enum { e } *E; |
| 311 |
void f(E); |
| 312 |
void g(E e) { f(e); } |
| 313 |
|
| 314 |
struct S { |
| 315 |
// FIXME: Should reject this: 'f' has linkage but its type does not, |
| 316 |
// and 'f' is odr-used but not defined in this TU. |
| 317 |
typedef enum { e } *E; |
| 318 |
void f(E); |
| 319 |
}; |
| 320 |
void g(S s, S::E e) { s.f(e); } |
| 321 |
} // namespace cwg216 |
| 322 |
|
| 323 |
namespace cwg217 { // cwg217: 2.7 |
| 324 |
template<typename T> struct S { |
| 325 |
void f(int); |
| 326 |
}; |
| 327 |
template<typename T> void S<T>::f(int = 0) {} |
| 328 |
// expected-error@-1 {{default arguments cannot be added to an out-of-line definition of a member of a class template}} |
| 329 |
} // namespace cwg217 |
| 330 |
|
| 331 |
namespace cwg218 { // cwg218: 2.7 |
| 332 |
// NB: also dup 405 |
| 333 |
namespace A { |
| 334 |
struct S {}; |
| 335 |
void f(S); |
| 336 |
} |
| 337 |
namespace B { |
| 338 |
struct S {}; |
| 339 |
void f(S); |
| 340 |
} |
| 341 |
|
| 342 |
struct C { |
| 343 |
int f; |
| 344 |
void test1(A::S as) { f(as); } |
| 345 |
// expected-error@-1 {{called object type 'int' is not a function or function pointer}} |
| 346 |
void test2(A::S as) { void f(); f(as); } |
| 347 |
// expected-error@-1 {{too many arguments to function call, expected 0, have 1}} |
| 348 |
// expected-note@-2 {{'f' declared here}} |
| 349 |
void test3(A::S as) { using A::f; f(as); } // ok |
| 350 |
void test4(A::S as) { using B::f; f(as); } // ok |
| 351 |
void test5(A::S as) { int f; f(as); } |
| 352 |
// expected-error@-1 {{called object type 'int' is not a function or function pointer}} |
| 353 |
void test6(A::S as) { struct f {}; (void) f(as); } |
| 354 |
// expected-error@-1 {{no matching conversion for functional-style cast from 'A::S' to 'f'}} |
| 355 |
// expected-note@-2 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A::S' to 'const f' for 1st argument}} |
| 356 |
// since-cxx11-note@-3 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A::S' to 'f' for 1st argument}} |
| 357 |
// expected-note@-4 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}} |
| 358 |
}; |
| 359 |
|
| 360 |
namespace D { |
| 361 |
struct S {}; |
| 362 |
struct X { void operator()(S); } f; |
| 363 |
} |
| 364 |
void testD(D::S ds) { f(ds); } |
| 365 |
// expected-error@-1 {{use of undeclared identifier 'f'}} |
| 366 |
|
| 367 |
namespace E { |
| 368 |
struct S {}; |
| 369 |
struct f { f(S); }; |
| 370 |
} |
| 371 |
void testE(E::S es) { f(es); } |
| 372 |
// expected-error@-1 {{use of undeclared identifier 'f'}} |
| 373 |
|
| 374 |
namespace F { |
| 375 |
struct S { |
| 376 |
template<typename T> friend void f(S, T) {} |
| 377 |
}; |
| 378 |
} |
| 379 |
void testF(F::S fs) { f(fs, 0); } |
| 380 |
|
| 381 |
namespace G { |
| 382 |
namespace X { |
| 383 |
int f; |
| 384 |
struct A {}; |
| 385 |
} |
| 386 |
namespace Y { |
| 387 |
template<typename T> void f(T); |
| 388 |
struct B {}; |
| 389 |
} |
| 390 |
template<typename A, typename B> struct C {}; |
| 391 |
} |
| 392 |
void testG(G::C<G::X::A, G::Y::B> gc) { f(gc); } |
| 393 |
} // namespace cwg218 |
| 394 |
|
| 395 |
// cwg219: na |
| 396 |
// cwg220: na |
| 397 |
|
| 398 |
namespace cwg221 { // cwg221: 3.6 |
| 399 |
struct A { // #cwg221-S |
| 400 |
A &operator=(int&); // #cwg221-S-copy-assign |
| 401 |
A &operator+=(int&); |
| 402 |
static A &operator=(A&, double&); |
| 403 |
// expected-error@-1 {{overloaded 'operator=' cannot be a static member function}} |
| 404 |
static A &operator+=(A&, double&); |
| 405 |
// expected-error@-1 {{overloaded 'operator+=' cannot be a static member function}} |
| 406 |
friend A &operator=(A&, char&); |
| 407 |
// expected-error@-1 {{overloaded 'operator=' must be a non-static member function}} |
| 408 |
friend A &operator+=(A&, char&); |
| 409 |
}; |
| 410 |
A &operator=(A&, float&); |
| 411 |
// expected-error@-1 {{overloaded 'operator=' must be a non-static member function}} |
| 412 |
A &operator+=(A&, float&); |
| 413 |
|
| 414 |
void test(A a, int n, char c, float f) { |
| 415 |
a = n; |
| 416 |
a += n; |
| 417 |
a = c; |
| 418 |
// expected-error@-1 {{no viable overloaded '='}} |
| 419 |
// expected-note@#cwg221-S-copy-assign {{candidate function not viable: no known conversion from 'char' to 'int &' for 1st argument}} |
| 420 |
// since-cxx11-note@#cwg221-S {{candidate function (the implicit move assignment operator) not viable: no known conversion from 'char' to 'A' for 1st argument}} |
| 421 |
// expected-note@#cwg221-S {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'char' to 'const A' for 1st argument}} |
| 422 |
a += c; |
| 423 |
a = f; |
| 424 |
// expected-error@-1 {{no viable overloaded '='}} |
| 425 |
// expected-note@#cwg221-S-copy-assign {{candidate function not viable: no known conversion from 'float' to 'int &' for 1st argument}} |
| 426 |
// since-cxx11-note@#cwg221-S {{candidate function (the implicit move assignment operator) not viable: no known conversion from 'float' to 'A' for 1st argument}} |
| 427 |
// expected-note@#cwg221-S {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'float' to 'const A' for 1st argument}} |
| 428 |
a += f; |
| 429 |
} |
| 430 |
} // namespace cwg221 |
| 431 |
|
| 432 |
namespace cwg222 { // cwg222: dup 637 |
| 433 |
void f(int a, int b, int c, int *x) { |
| 434 |
#pragma clang diagnostic push |
| 435 |
#pragma clang diagnostic warning "-Wunsequenced" |
| 436 |
void((a += b) += c); |
| 437 |
void((a += b) + (a += c)); |
| 438 |
// expected-warning@-1 {{multiple unsequenced modifications to 'a'}} |
| 439 |
|
| 440 |
x[a++] = a; |
| 441 |
// cxx98-14-warning@-1 {{unsequenced modification and access to 'a'}} |
| 442 |
|
| 443 |
a = b = 0; // ok, read and write of 'b' are sequenced |
| 444 |
|
| 445 |
a = (b = a++); |
| 446 |
// cxx98-14-warning@-1 {{multiple unsequenced modifications to 'a'}} |
| 447 |
a = (b = ++a); |
| 448 |
#pragma clang diagnostic pop |
| 449 |
} |
| 450 |
} // namespace cwg222 |
| 451 |
|
| 452 |
// cwg223: na |
| 453 |
|
| 454 |
namespace cwg224 { // cwg224: 16 |
| 455 |
namespace example1 { |
| 456 |
template <class T> class A { |
| 457 |
typedef int type; |
| 458 |
A::type a; |
| 459 |
A<T>::type b; |
| 460 |
A<T*>::type c; |
| 461 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'A<T *>::type' is a C++20 extension}} |
| 462 |
::cwg224::example1::A<T>::type d; |
| 463 |
|
| 464 |
class B { |
| 465 |
typedef int type; |
| 466 |
|
| 467 |
A::type a; |
| 468 |
A<T>::type b; |
| 469 |
A<T*>::type c; |
| 470 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'A<T *>::type' is a C++20 extension}} |
| 471 |
::cwg224::example1::A<T>::type d; |
| 472 |
|
| 473 |
B::type e; |
| 474 |
A<T>::B::type f; |
| 475 |
A<T*>::B::type g; |
| 476 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'A<T *>::B::type' is a C++20 extension}} |
| 477 |
typename A<T*>::B::type h; |
| 478 |
}; |
| 479 |
}; |
| 480 |
|
| 481 |
template <class T> class A<T*> { |
| 482 |
typedef int type; |
| 483 |
A<T*>::type a; |
| 484 |
A<T>::type b; |
| 485 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'A<T>::type' is a C++20 extension}} |
| 486 |
}; |
| 487 |
|
| 488 |
template <class T1, class T2, int I> struct B { |
| 489 |
typedef int type; |
| 490 |
B<T1, T2, I>::type b1; |
| 491 |
B<T2, T1, I>::type b2; |
| 492 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'B<T2, T1, I>::type' is a C++20 extension}} |
| 493 |
|
| 494 |
typedef T1 my_T1; |
| 495 |
static const int my_I = I; |
| 496 |
static const int my_I2 = I+0; |
| 497 |
static const int my_I3 = my_I; |
| 498 |
B<my_T1, T2, my_I>::type b3; |
| 499 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'B<my_T1, T2, my_I>::type' is a C++20 extension}} |
| 500 |
B<my_T1, T2, my_I2>::type b4; |
| 501 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'B<my_T1, T2, my_I2>::type' is a C++20 extension}} |
| 502 |
B<my_T1, T2, my_I3>::type b5; |
| 503 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'B<my_T1, T2, my_I3>::type' is a C++20 extension}} |
| 504 |
}; |
| 505 |
} |
| 506 |
|
| 507 |
namespace example2 { |
| 508 |
template <int, typename T> struct X { typedef T type; }; |
| 509 |
template <class T> class A { |
| 510 |
static const int i = 5; |
| 511 |
X<i, int>::type w; |
| 512 |
X<A::i, char>::type x; |
| 513 |
X<A<T>::i, double>::type y; |
| 514 |
X<A<T*>::i, long>::type z; |
| 515 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'X<A<T *>::i, long>::type' is a C++20 extension}} |
| 516 |
int f(); |
| 517 |
}; |
| 518 |
template <class T> int A<T>::f() { |
| 519 |
return i; |
| 520 |
} |
| 521 |
} |
| 522 |
} // namespace cwg224 |
| 523 |
|
| 524 |
// cwg225: yes |
| 525 |
template<typename T> void cwg225_f(T t) { cwg225_g(t); } |
| 526 |
// expected-error@-1 {{call to function 'cwg225_g' that is neither visible in the template definition nor found by argument-dependent lookup}} |
| 527 |
// expected-note@#cwg225-f {{in instantiation of function template specialization 'cwg225_f<int>' requested here}} |
| 528 |
// expected-note@#cwg225-g {{'cwg225_g' should be declared prior to the call site}} |
| 529 |
void cwg225_g(int); // #cwg225-g |
| 530 |
template void cwg225_f(int); // #cwg225-f |
| 531 |
|
| 532 |
namespace cwg226 { // cwg226: no |
| 533 |
// FIXME: This appears to be wrong: default arguments for function templates |
| 534 |
// are listed as a defect (in c++98) not an extension. EDG accepts them in |
| 535 |
// strict c++98 mode. |
| 536 |
template<typename T = void> void f() {} |
| 537 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 538 |
template<typename T> struct S { |
| 539 |
template<typename U = void> void g(); |
| 540 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 541 |
template<typename U> struct X; |
| 542 |
template<typename U> void h(); |
| 543 |
}; |
| 544 |
template<typename T> template<typename U> void S<T>::g() {} |
| 545 |
template<typename T> template<typename U = void> struct S<T>::X {}; |
| 546 |
// expected-error@-1 {{cannot add a default template argument to the definition of a member of a class template}} |
| 547 |
template<typename T> template<typename U = void> void S<T>::h() {} |
| 548 |
// expected-error@-1 {{cannot add a default template argument to the definition of a member of a class template}} |
| 549 |
|
| 550 |
template<typename> void friend_h(); |
| 551 |
struct A { |
| 552 |
// FIXME: This is ill-formed. |
| 553 |
template<typename=void> struct friend_B; |
| 554 |
// FIXME: f, h, and i are ill-formed. |
| 555 |
// f is ill-formed because it is not a definition. |
| 556 |
// h and i are ill-formed because they are not the only declarations of the |
| 557 |
// function in the translation unit. |
| 558 |
template<typename=void> void friend_f(); |
| 559 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 560 |
template<typename=void> void friend_g() {} |
| 561 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 562 |
template<typename=void> void friend_h() {} |
| 563 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 564 |
template<typename=void> void friend_i() {} |
| 565 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 566 |
}; |
| 567 |
template<typename> void friend_i(); |
| 568 |
|
| 569 |
template<typename=void, typename X> void foo(X) {} |
| 570 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 571 |
template<typename=void, typename X> struct Foo {}; |
| 572 |
// expected-error@-1 {{template parameter missing a default argument}} |
| 573 |
// expected-note@-2 {{previous default template argument defined here}} |
| 574 |
|
| 575 |
template<typename=void, typename X, typename, typename Y> int foo(X, Y); |
| 576 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 577 |
template<typename, typename X, typename=void, typename Y> int foo(X, Y); |
| 578 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 579 |
int x = foo(0, 0); |
| 580 |
} // namespace cwg226 |
| 581 |
|
| 582 |
namespace cwg227 { // cwg227: 2.7 |
| 583 |
void f(bool b) { |
| 584 |
if (b) |
| 585 |
int n; |
| 586 |
else |
| 587 |
int n; |
| 588 |
} |
| 589 |
} // namespace cwg227 |
| 590 |
|
| 591 |
namespace cwg228 { // cwg228: 2.7 |
| 592 |
template <class T> struct X { |
| 593 |
void f(); |
| 594 |
}; |
| 595 |
template <class T> struct Y { |
| 596 |
void g(X<T> x) { x.template X<T>::f(); } |
| 597 |
}; |
| 598 |
} // namespace cwg228 |
| 599 |
|
| 600 |
namespace cwg229 { // cwg229: 2.9 |
| 601 |
template<typename T> void f(); |
| 602 |
template<typename T> void f<T*>() {} |
| 603 |
// expected-error@-1 {{function template partial specialization is not allowed}} |
| 604 |
template<> void f<int>() {} |
| 605 |
} // namespace cwg229 |
| 606 |
|
| 607 |
namespace cwg230 { // cwg230: 3.0 |
| 608 |
struct S { |
| 609 |
S() { f(); } |
| 610 |
// expected-warning@-1 {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'cwg230::S'}} |
| 611 |
// expected-note@#cwg230-f {{'f' declared here}} |
| 612 |
virtual void f() = 0; // #cwg230-f |
| 613 |
}; |
| 614 |
} // namespace cwg230 |
| 615 |
|
| 616 |
namespace cwg231 { // cwg231: 2.7 |
| 617 |
namespace outer { |
| 618 |
namespace inner { |
| 619 |
int i; // #cwg231-i |
| 620 |
} |
| 621 |
void f() { using namespace inner; } |
| 622 |
int j = i; |
| 623 |
// expected-error@-1 {{use of undeclared identifier 'i'; did you mean 'inner::i'?}} |
| 624 |
// expected-note@#cwg231-i {{'inner::i' declared here}} |
| 625 |
} |
| 626 |
} // namespace cwg231 |
| 627 |
|
| 628 |
// 232 is NAD; the desired behavior is described in 2823. |
| 629 |
// cwg232: dup 2823 |
| 630 |
|
| 631 |
// cwg234: na |
| 632 |
// cwg235: na |
| 633 |
|
| 634 |
namespace cwg236 { // cwg236: 3.2 |
| 635 |
void *p = int(); |
| 636 |
// cxx98-warning@-1 {{expression which evaluates to zero treated as a null pointer constant of type 'void *'}} |
| 637 |
// since-cxx11-error@-2 {{cannot initialize a variable of type 'void *' with an rvalue of type 'int'}} |
| 638 |
} // namespace cwg236 |
| 639 |
|
| 640 |
namespace cwg237 { // cwg237: dup 470 |
| 641 |
template<typename T> struct A { void f() { T::error; } }; |
| 642 |
template<typename T> struct B : A<T> {}; |
| 643 |
template struct B<int>; // ok |
| 644 |
} // namespace cwg237 |
| 645 |
|
| 646 |
namespace cwg239 { // cwg239: 2.7 |
| 647 |
namespace NS { |
| 648 |
class T {}; |
| 649 |
void f(T); |
| 650 |
float &g(T, int); |
| 651 |
} |
| 652 |
NS::T parm; |
| 653 |
int &g(NS::T, float); |
| 654 |
int main() { |
| 655 |
f(parm); |
| 656 |
float &r = g(parm, 1); |
| 657 |
extern int &g(NS::T, float); |
| 658 |
int &s = g(parm, 1); |
| 659 |
} |
| 660 |
} // namespace cwg239 |
| 661 |
|
| 662 |
// cwg240: dup 616 |
| 663 |
|
| 664 |
namespace cwg241 { // cwg241: 9 |
| 665 |
namespace A { |
| 666 |
struct B {}; |
| 667 |
template <int X> void f(); // #cwg241-A-f |
| 668 |
template <int X> void g(B); |
| 669 |
} |
| 670 |
namespace C { |
| 671 |
template <class T> void f(T t); // #cwg241-C-f |
| 672 |
template <class T> void g(T t); // #cwg241-C-g |
| 673 |
} |
| 674 |
void h(A::B b) { |
| 675 |
f<3>(b); |
| 676 |
// expected-error@-1 {{no matching function for call to 'f'}} |
| 677 |
// expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}} |
| 678 |
// cxx98-17-error@-3 {{use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension}} |
| 679 |
g<3>(b); |
| 680 |
// cxx98-17-error@-1 {{use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension}} |
| 681 |
A::f<3>(b); |
| 682 |
// expected-error@-1 {{no matching function for call to 'f'}} |
| 683 |
// expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}} |
| 684 |
A::g<3>(b); |
| 685 |
C::f<3>(b); |
| 686 |
// expected-error@-1 {{no matching function for call to 'f'}} |
| 687 |
// expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}} |
| 688 |
C::g<3>(b); |
| 689 |
// expected-error@-1 {{no matching function for call to 'g'}} |
| 690 |
// expected-note@#cwg241-C-g {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}} |
| 691 |
using C::f; |
| 692 |
using C::g; |
| 693 |
f<3>(b); |
| 694 |
// expected-error@-1 {{no matching function for call to 'f'}} |
| 695 |
// expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}} |
| 696 |
// expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}} |
| 697 |
g<3>(b); |
| 698 |
} |
| 699 |
} // namespace cwg241 |
| 700 |
|
| 701 |
namespace cwg243 { // cwg243: 2.8 |
| 702 |
struct B; |
| 703 |
struct A { |
| 704 |
A(B); // #cwg243-A |
| 705 |
}; |
| 706 |
struct B { |
| 707 |
operator A() = delete; // #cwg243-B |
| 708 |
// cxx98-error@-1 {{deleted function definitions are a C++11 extension}} |
| 709 |
} b; |
| 710 |
A a1(b); |
| 711 |
A a2 = b; |
| 712 |
// expected-error@-1 {{conversion from 'struct B' to 'A' is ambiguous}} |
| 713 |
// expected-note@#cwg243-A {{candidate constructor}} |
| 714 |
// expected-note@#cwg243-B {{candidate function has been explicitly deleted}} |
| 715 |
} // namespace cwg243 |
| 716 |
|
| 717 |
namespace cwg244 { // cwg244: 11 |
| 718 |
// NB: this test is reused by cwg399 |
| 719 |
struct B {}; // #cwg244-B |
| 720 |
struct D : B {}; |
| 721 |
|
| 722 |
D D_object; |
| 723 |
typedef B B_alias; |
| 724 |
B* B_ptr = &D_object; |
| 725 |
|
| 726 |
void f() { |
| 727 |
D_object.~B(); |
| 728 |
// expected-error@-1 {{destructor type 'B' in object destruction expression does not match the type 'D' of the object being destroyed}} |
| 729 |
// expected-note@#cwg244-B {{type 'B' found by destructor name lookup}} |
| 730 |
D_object.B::~B(); |
| 731 |
D_object.D::~B(); // FIXME: Missing diagnostic for this. |
| 732 |
B_ptr->~B(); |
| 733 |
B_ptr->~B_alias(); |
| 734 |
B_ptr->B_alias::~B(); |
| 735 |
B_ptr->B_alias::~B_alias(); |
| 736 |
B_ptr->cwg244::~B(); |
| 737 |
// expected-error@-1 {{no member named '~B' in namespace 'cwg244'}} |
| 738 |
B_ptr->cwg244::~B_alias(); |
| 739 |
// expected-error@-1 {{no member named '~B' in namespace 'cwg244'}} |
| 740 |
} |
| 741 |
|
| 742 |
template<typename T, typename U> |
| 743 |
void f(T *B_ptr, U D_object) { |
| 744 |
D_object.~B(); // FIXME: Missing diagnostic for this. |
| 745 |
D_object.B::~B(); |
| 746 |
D_object.D::~B(); // FIXME: Missing diagnostic for this. |
| 747 |
B_ptr->~B(); |
| 748 |
B_ptr->~B_alias(); |
| 749 |
B_ptr->B_alias::~B(); |
| 750 |
B_ptr->B_alias::~B_alias(); |
| 751 |
B_ptr->cwg244::~B(); |
| 752 |
// expected-error@-1 {{'cwg244' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}} |
| 753 |
B_ptr->cwg244::~B_alias(); |
| 754 |
// expected-error@-1 {{'cwg244' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}} |
| 755 |
} |
| 756 |
template void f<B, D>(B*, D); |
| 757 |
|
| 758 |
namespace N { |
| 759 |
template<typename T> struct E {}; |
| 760 |
typedef E<int> F; |
| 761 |
} |
| 762 |
void g(N::F f) { |
| 763 |
typedef N::F G; // #cwg244-G |
| 764 |
f.~G(); |
| 765 |
f.G::~E(); |
| 766 |
// expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}} |
| 767 |
f.G::~F(); |
| 768 |
// expected-error@-1 {{undeclared identifier 'F' in destructor name}} |
| 769 |
f.G::~G(); |
| 770 |
// This is technically ill-formed; E is looked up in 'N::' and names the |
| 771 |
// class template, not the injected-class-name of the class. But that's |
| 772 |
// probably a bug in the standard. |
| 773 |
f.N::F::~E(); |
| 774 |
// expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}} |
| 775 |
// This is valid; we look up the second F in the same scope in which we |
| 776 |
// found the first one, that is, 'N::'. |
| 777 |
f.N::F::~F(); |
| 778 |
// This is technically ill-formed; G is looked up in 'N::' and is not found. |
| 779 |
// Rejecting this seems correct, but most compilers accept, so we do also. |
| 780 |
f.N::F::~G(); |
| 781 |
// expected-error@-1 {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}} |
| 782 |
// expected-note@#cwg244-G {{type 'G' (aka 'E<int>') found by destructor name lookup}} |
| 783 |
} |
| 784 |
|
| 785 |
// Bizarrely, compilers perform lookup in the scope for qualified destructor |
| 786 |
// names, if the nested-name-specifier is non-dependent. Ensure we diagnose |
| 787 |
// this. |
| 788 |
namespace QualifiedLookupInScope { |
| 789 |
namespace N { |
| 790 |
template <typename> struct S { struct Inner {}; }; |
| 791 |
} |
| 792 |
template <typename U> void f(typename N::S<U>::Inner *p) { |
| 793 |
typedef typename N::S<U>::Inner T; |
| 794 |
p->::cwg244::QualifiedLookupInScope::N::S<U>::Inner::~T(); |
| 795 |
// expected-error@-1 {{no type named 'T' in 'cwg244::QualifiedLookupInScope::N::S<int>'}} |
| 796 |
// expected-note@#cwg244-f {{in instantiation of function template specialization 'cwg244::QualifiedLookupInScope::f<int>' requested here}} |
| 797 |
} |
| 798 |
template void f<int>(N::S<int>::Inner *); // #cwg244-f |
| 799 |
|
| 800 |
template <typename U> void g(U *p) { |
| 801 |
typedef U T; |
| 802 |
p->T::~T(); |
| 803 |
p->U::~T(); |
| 804 |
p->::cwg244::QualifiedLookupInScope::N::S<int>::Inner::~T(); |
| 805 |
// expected-error@-1 {{'T' does not refer to a type name in pseudo-destructor expression; expected the name of type 'U'}} |
| 806 |
} |
| 807 |
template void g(N::S<int>::Inner *); |
| 808 |
} |
| 809 |
} // namespace cwg244 |
| 810 |
|
| 811 |
namespace cwg245 { // cwg245: 2.8 |
| 812 |
struct S { |
| 813 |
enum E {}; // #cwg245-E |
| 814 |
class E *p; |
| 815 |
// expected-error@-1 {{use of 'E' with tag type that does not match previous declaration}} |
| 816 |
// expected-note@#cwg245-E {{previous use is here}} |
| 817 |
}; |
| 818 |
} // namespace cwg245 |
| 819 |
|
| 820 |
namespace cwg246 { // cwg246: 3.2 |
| 821 |
struct S { |
| 822 |
S() try { // #cwg246-try |
| 823 |
throw 0; |
| 824 |
X: ; |
| 825 |
} catch (int) { |
| 826 |
goto X; |
| 827 |
// expected-error@-1 {{cannot jump from this goto statement to its label}} |
| 828 |
// expected-note@#cwg246-try {{jump bypasses initialization of try block}} |
| 829 |
} |
| 830 |
}; |
| 831 |
} // namespace cwg246 |
| 832 |
|
| 833 |
namespace cwg247 { // cwg247: 2.7 |
| 834 |
struct A {}; |
| 835 |
struct B : A { |
| 836 |
void f(); |
| 837 |
void f(int); |
| 838 |
}; |
| 839 |
void (A::*f)() = (void (A::*)())&B::f; |
| 840 |
|
| 841 |
struct C { |
| 842 |
void f(); |
| 843 |
void f(int); |
| 844 |
}; |
| 845 |
struct D : C {}; |
| 846 |
void (C::*g)() = &D::f; |
| 847 |
void (D::*h)() = &D::f; |
| 848 |
|
| 849 |
struct E { |
| 850 |
void f(); |
| 851 |
}; |
| 852 |
struct F : E { |
| 853 |
using E::f; |
| 854 |
void f(int); |
| 855 |
}; |
| 856 |
void (F::*i)() = &F::f; |
| 857 |
} // namespace cwg247 |
| 858 |
|
| 859 |
namespace cwg248 { // cwg248: sup P1949 |
| 860 |
int \u040d\u040e = 0; |
| 861 |
} // namespace cwg248 |
| 862 |
|
| 863 |
namespace cwg249 { // cwg249: 2.7 |
| 864 |
template<typename T> struct X { void f(); }; |
| 865 |
template<typename T> void X<T>::f() {} |
| 866 |
} // namespace cwg249 |
| 867 |
|
| 868 |
namespace cwg250 { // cwg250: 2.7 |
| 869 |
typedef void (*FPtr)(double x[]); |
| 870 |
|
| 871 |
template<int I> void f(double x[]); |
| 872 |
FPtr fp = &f<3>; |
| 873 |
|
| 874 |
template<int I = 3> void g(double x[]); |
| 875 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 876 |
FPtr gp = &g<>; |
| 877 |
} // namespace cwg250 |
| 878 |
|
| 879 |
namespace cwg252 { // cwg252: 3.1 |
| 880 |
struct A { |
| 881 |
void operator delete(void*); // #cwg252-A |
| 882 |
}; |
| 883 |
struct B { |
| 884 |
void operator delete(void*); // #cwg252-B |
| 885 |
}; |
| 886 |
struct C : A, B { |
| 887 |
virtual ~C(); |
| 888 |
}; |
| 889 |
C::~C() {} |
| 890 |
// expected-error@-1 {{member 'operator delete' found in multiple base classes of different types}} |
| 891 |
// expected-note@#cwg252-A {{member found by ambiguous name lookup}} |
| 892 |
// expected-note@#cwg252-B {{member found by ambiguous name lookup}} |
| 893 |
|
| 894 |
struct D { |
| 895 |
void operator delete(void*, int); // #cwg252-D |
| 896 |
virtual ~D(); |
| 897 |
}; |
| 898 |
D::~D() {} |
| 899 |
// expected-error@-1 {{no suitable member 'operator delete' in 'D'}} |
| 900 |
// expected-note@#cwg252-D {{member 'operator delete' declared here}} |
| 901 |
|
| 902 |
struct E { |
| 903 |
void operator delete(void*, int); |
| 904 |
void operator delete(void*) = delete; // #cwg252-E |
| 905 |
// cxx98-error@-1 {{deleted function definitions are a C++11 extension}} |
| 906 |
virtual ~E(); |
| 907 |
}; |
| 908 |
E::~E() {} |
| 909 |
// expected-error@-1 {{attempt to use a deleted function}} |
| 910 |
// expected-note@#cwg252-E {{'operator delete' has been explicitly marked deleted here}} |
| 911 |
|
| 912 |
struct F { |
| 913 |
// If both functions are available, the first one is a placement delete. |
| 914 |
void operator delete(void*, size_t); |
| 915 |
void operator delete(void*) = delete; // #cwg252-F |
| 916 |
// cxx98-error@-1 {{deleted function definitions are a C++11 extension}} |
| 917 |
virtual ~F(); |
| 918 |
}; |
| 919 |
F::~F() {} |
| 920 |
// expected-error@-1 {{attempt to use a deleted function}} |
| 921 |
// expected-note@#cwg252-F {{'operator delete' has been explicitly marked deleted here}} |
| 922 |
|
| 923 |
struct G { |
| 924 |
void operator delete(void*, size_t); |
| 925 |
virtual ~G(); |
| 926 |
}; |
| 927 |
G::~G() {} |
| 928 |
} // namespace cwg252 |
| 929 |
|
| 930 |
namespace cwg254 { // cwg254: 2.9 |
| 931 |
template<typename T> struct A { |
| 932 |
typedef typename T::type type; // ok even if this is a typedef-name, because |
| 933 |
// it's not an elaborated-type-specifier |
| 934 |
typedef struct T::type foo; |
| 935 |
// expected-error@-1 {{typedef 'type' cannot be referenced with the 'struct' specifier}} |
| 936 |
// expected-note@#cwg254-instantiation {{in instantiation of template class 'cwg254::A<cwg254::C>' requested here}} |
| 937 |
// expected-note@#cwg254-C {{declared here}} |
| 938 |
}; |
| 939 |
struct B { struct type {}; }; |
| 940 |
struct C { typedef struct {} type; }; // #cwg254-C |
| 941 |
A<B>::type n; |
| 942 |
A<C>::type n; // #cwg254-instantiation |
| 943 |
} // namespace cwg254 |
| 944 |
|
| 945 |
namespace cwg255 { // cwg255: 2.7 |
| 946 |
struct S { |
| 947 |
void operator delete(void *){} |
| 948 |
void operator delete(void *, int){} |
| 949 |
}; |
| 950 |
void f(S *p) { delete p; } |
| 951 |
} // namespace cwg255 |
| 952 |
|
| 953 |
// cwg256: dup 624 |
| 954 |
|
| 955 |
namespace cwg257 { // cwg257: 3.4 |
| 956 |
struct A { A(int); }; // #cwg257-A |
| 957 |
struct B : virtual A { |
| 958 |
B() {} |
| 959 |
virtual void f() = 0; |
| 960 |
}; |
| 961 |
struct C : B { |
| 962 |
C() {} |
| 963 |
}; |
| 964 |
struct D : B { |
| 965 |
D() {} |
| 966 |
// expected-error@-1 {{constructor for 'cwg257::D' must explicitly initialize the base class 'A' which does not have a default constructor}} |
| 967 |
// expected-note@#cwg257-A {{'cwg257::A' declared here}} |
| 968 |
void f(); |
| 969 |
}; |
| 970 |
} // namespace cwg257 |
| 971 |
|
| 972 |
namespace cwg258 { // cwg258: 2.8 |
| 973 |
struct A { |
| 974 |
void f(const int); |
| 975 |
template<typename> void g(int); |
| 976 |
float &h() const; |
| 977 |
}; |
| 978 |
struct B : A { |
| 979 |
using A::f; |
| 980 |
using A::g; |
| 981 |
using A::h; |
| 982 |
int &f(int); |
| 983 |
template<int> int &g(int); // #cwg258-B-g |
| 984 |
int &h(); |
| 985 |
} b; |
| 986 |
int &w = b.f(0); |
| 987 |
int &x = b.g<int>(0); |
| 988 |
// expected-error@-1 {{no matching member function for call to 'g'}} |
| 989 |
// expected-note@#cwg258-B-g {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}} |
| 990 |
int &y = b.h(); |
| 991 |
float &z = const_cast<const B&>(b).h(); |
| 992 |
|
| 993 |
struct C { |
| 994 |
virtual void f(const int) = 0; |
| 995 |
}; |
| 996 |
struct D : C { |
| 997 |
void f(int); |
| 998 |
} d; |
| 999 |
|
| 1000 |
struct E { |
| 1001 |
virtual void f() = 0; // #cwg258-E-f |
| 1002 |
}; |
| 1003 |
struct F : E { |
| 1004 |
void f() const {} |
| 1005 |
} f; |
| 1006 |
// expected-error@-1 {{variable type 'struct F' is an abstract class}} |
| 1007 |
// expected-note@#cwg258-E-f {{unimplemented pure virtual method 'f' in 'F'}} |
| 1008 |
} // namespace cwg258 |
| 1009 |
|
| 1010 |
namespace cwg259 { // cwg259: 4 |
| 1011 |
template<typename T> struct A {}; |
| 1012 |
template struct A<int>; // #cwg259-A-int |
| 1013 |
template struct A<int>; |
| 1014 |
// expected-error@-1 {{duplicate explicit instantiation of 'A<int>'}} |
| 1015 |
// expected-note@#cwg259-A-int {{previous explicit instantiation is here}} |
| 1016 |
|
| 1017 |
template<> struct A<float>; // #cwg259-A-float |
| 1018 |
template struct A<float>; |
| 1019 |
// expected-warning@-1 {{explicit instantiation of 'A<float>' that occurs after an explicit specialization has no effect}} |
| 1020 |
// expected-note@#cwg259-A-float {{previous template specialization is here}} |
| 1021 |
|
| 1022 |
template struct A<char>; // #cwg259-A-char |
| 1023 |
template<> struct A<char>; |
| 1024 |
// expected-error@-1 {{explicit specialization of 'cwg259::A<char>' after instantiation}} |
| 1025 |
// expected-note@#cwg259-A-char {{explicit instantiation first required here}} |
| 1026 |
|
| 1027 |
template<> struct A<double>; |
| 1028 |
template<> struct A<double>; |
| 1029 |
template<> struct A<double> {}; // #cwg259-A-double |
| 1030 |
template<> struct A<double> {}; |
| 1031 |
// expected-error@-1 {{redefinition of 'A<double>'}} |
| 1032 |
// expected-note@#cwg259-A-double {{previous definition is here}} |
| 1033 |
|
| 1034 |
template<typename T> struct B; // #cwg259-B |
| 1035 |
template struct B<int>; |
| 1036 |
// expected-error@-1 {{explicit instantiation of undefined template 'cwg259::B<int>'}} |
| 1037 |
// expected-note@#cwg259-B {{template is declared here}} |
| 1038 |
|
| 1039 |
template<> struct B<float>; // #cwg259-B-float |
| 1040 |
template struct B<float>; |
| 1041 |
// expected-warning@-1 {{explicit instantiation of 'B<float>' that occurs after an explicit specialization has no effect}} |
| 1042 |
// expected-note@#cwg259-B-float {{previous template specialization is here}} |
| 1043 |
} // namespace cwg259 |
| 1044 |
|
| 1045 |
// FIXME: When cwg260 is resolved, also add tests for CWG507. |
| 1046 |
|
| 1047 |
namespace cwg261 { // cwg261: no |
| 1048 |
#pragma clang diagnostic push |
| 1049 |
#pragma clang diagnostic warning "-Wused-but-marked-unused" |
| 1050 |
|
| 1051 |
// FIXME: This is ill-formed, with a diagnostic required, because operator new |
| 1052 |
// and operator delete are inline and odr-used, but not defined in this |
| 1053 |
// translation unit. |
| 1054 |
// We're also missing the -Wused-but-marked-unused diagnostic here. |
| 1055 |
struct A { |
| 1056 |
inline void *operator new(size_t) __attribute__((unused)); |
| 1057 |
inline void operator delete(void*) __attribute__((unused)); |
| 1058 |
A() {} |
| 1059 |
}; |
| 1060 |
|
| 1061 |
// FIXME: This is ill-formed, with a required diagnostic, for the same |
| 1062 |
// reason. |
| 1063 |
struct B { |
| 1064 |
inline void operator delete(void*) __attribute__((unused)); |
| 1065 |
~B() {} |
| 1066 |
}; |
| 1067 |
struct C { |
| 1068 |
inline void operator delete(void*) __attribute__((unused)); |
| 1069 |
virtual ~C() {} |
| 1070 |
// expected-warning@-1 {{'operator delete' was marked unused but was used}} |
| 1071 |
}; |
| 1072 |
|
| 1073 |
struct D { |
| 1074 |
inline void operator delete(void*) __attribute__((unused)); |
| 1075 |
}; |
| 1076 |
void h() { C::operator delete(0); } |
| 1077 |
// expected-warning@-1 {{'operator delete' was marked unused but was used}} |
| 1078 |
|
| 1079 |
#pragma clang diagnostic pop |
| 1080 |
} // namespace cwg261 |
| 1081 |
|
| 1082 |
namespace cwg262 { // cwg262: 2.7 |
| 1083 |
int f(int = 0, ...); |
| 1084 |
int k = f(); |
| 1085 |
int l = f(0); |
| 1086 |
int m = f(0, 0); |
| 1087 |
} // namespace cwg262 |
| 1088 |
|
| 1089 |
namespace cwg263 { // cwg263: 3.3 |
| 1090 |
struct X {}; |
| 1091 |
struct Y { |
| 1092 |
#if __cplusplus < 201103L |
| 1093 |
friend X::X() throw(); |
| 1094 |
friend X::~X() throw(); |
| 1095 |
#elif __cplusplus <= 201703L |
| 1096 |
friend constexpr X::X() noexcept; |
| 1097 |
friend X::~X(); |
| 1098 |
#else |
| 1099 |
friend constexpr X::X() noexcept; |
| 1100 |
friend constexpr X::~X(); |
| 1101 |
#endif |
| 1102 |
Y::Y(); |
| 1103 |
// expected-error@-1 {{extra qualification on member 'Y'}} |
| 1104 |
Y::~Y(); |
| 1105 |
// expected-error@-1 {{extra qualification on member '~Y'}} |
| 1106 |
}; |
| 1107 |
} // namespace cwg263 |
| 1108 |
|
| 1109 |
// cwg265: dup 353 |
| 1110 |
// cwg266: na |
| 1111 |
// cwg269: na |
| 1112 |
// cwg270: na |
| 1113 |
|
| 1114 |
namespace cwg272 { // cwg272: 2.7 |
| 1115 |
struct X { |
| 1116 |
void f() { |
| 1117 |
this->~X(); |
| 1118 |
X::~X(); |
| 1119 |
~X(); |
| 1120 |
// expected-error@-1 {{invalid argument type 'X' to unary expression}} |
| 1121 |
} |
| 1122 |
}; |
| 1123 |
} // namespace cwg272 |
| 1124 |
|
| 1125 |
// cwg273 is in cwg273.cpp |
| 1126 |
// cwg274: na |
| 1127 |
|
| 1128 |
namespace cwg275 { // cwg275: no |
| 1129 |
namespace N { |
| 1130 |
template <class T> void f(T) {} // #cwg275-N-f |
| 1131 |
template <class T> void g(T) {} // #cwg275-N-g |
| 1132 |
template <> void f(int); |
| 1133 |
template <> void f(char); |
| 1134 |
template <> void f(double); |
| 1135 |
template <> void g(char); |
| 1136 |
} |
| 1137 |
|
| 1138 |
using namespace N; |
| 1139 |
|
| 1140 |
namespace M { |
| 1141 |
template <> void N::f(char) {} |
| 1142 |
// expected-error@-1 {{cannot define or redeclare 'f' here because namespace 'M' does not enclose namespace 'N'}} |
| 1143 |
template <class T> void g(T) {} |
| 1144 |
template <> void g(char) {} |
| 1145 |
// FIXME: this should be rejected in c++98 too |
| 1146 |
template void f(long); |
| 1147 |
// since-cxx11-error@-1 {{explicit instantiation of 'cwg275::N::f' must occur in namespace 'N'}} |
| 1148 |
// since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}} |
| 1149 |
// FIXME: this should be rejected in c++98 too |
| 1150 |
template void N::f(unsigned long); |
| 1151 |
// since-cxx11-error@-1 {{explicit instantiation of 'f' not in a namespace enclosing 'N'}} |
| 1152 |
// since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}} |
| 1153 |
template void h(long); |
| 1154 |
// expected-error@-1 {{explicit instantiation of 'h' does not refer to a function template, variable template, member function, member class, or static data member}} |
| 1155 |
template <> void f(double) {} |
| 1156 |
// expected-error@-1 {{no function template matches function template specialization 'f'}} |
| 1157 |
} |
| 1158 |
|
| 1159 |
template <class T> void g(T) {} // #cwg275-g |
| 1160 |
|
| 1161 |
template <> void N::f(char) {} |
| 1162 |
template <> void f(int) {} |
| 1163 |
// expected-error@-1 {{no function template matches function template specialization 'f'}} |
| 1164 |
|
| 1165 |
// FIXME: this should be rejected in c++98 too |
| 1166 |
template void f(short); |
| 1167 |
// since-cxx11-error@-1 {{explicit instantiation of 'cwg275::N::f' must occur in namespace 'N'}} |
| 1168 |
// since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}} |
| 1169 |
template void N::f(unsigned short); |
| 1170 |
|
| 1171 |
// FIXME: this should probably be valid. the wording from the issue |
| 1172 |
// doesn't clarify this, but it follows from the usual rules. |
| 1173 |
template void g(int); |
| 1174 |
// expected-error@-1 {{partial ordering for explicit instantiation of 'g' is ambiguous}} |
| 1175 |
// expected-note@#cwg275-g {{explicit instantiation candidate function 'cwg275::g<int>' template here [with T = int]}} |
| 1176 |
// expected-note@#cwg275-N-g {{explicit instantiation candidate function 'cwg275::N::g<int>' template here [with T = int]}} |
| 1177 |
|
| 1178 |
// FIXME: likewise, this should also be valid. |
| 1179 |
template<typename T> void f(T) {} // #cwg275-f |
| 1180 |
template void f(short); |
| 1181 |
// expected-error@-1 {{partial ordering for explicit instantiation of 'f' is ambiguous}} |
| 1182 |
// expected-note@#cwg275-f {{explicit instantiation candidate function 'cwg275::f<short>' template here [with T = short]}} |
| 1183 |
// expected-note@#cwg275-N-f {{explicit instantiation candidate function 'cwg275::N::f<short>' template here [with T = short]}} |
| 1184 |
} // namespace cwg275 |
| 1185 |
|
| 1186 |
// cwg276: na |
| 1187 |
|
| 1188 |
namespace cwg277 { // cwg277: 3.1 |
| 1189 |
typedef int *intp; |
| 1190 |
int *p = intp(); |
| 1191 |
static_assert(__enable_constant_folding(!intp()), ""); |
| 1192 |
} // namespace cwg277 |
| 1193 |
|
| 1194 |
// cwg279 is in cwg279.cpp |
| 1195 |
|
| 1196 |
namespace cwg280 { // cwg280: 2.9 |
| 1197 |
typedef void f0(); |
| 1198 |
typedef void f1(int); |
| 1199 |
typedef void f2(int, int); |
| 1200 |
typedef void f3(int, int, int); |
| 1201 |
struct A { |
| 1202 |
operator f1*(); // #cwg280-A-f1 |
| 1203 |
operator f2*(); |
| 1204 |
}; |
| 1205 |
struct B { |
| 1206 |
operator f0*(); // #cwg280-B-f0 |
| 1207 |
private: |
| 1208 |
operator f3*(); // #cwg280-B-f3 |
| 1209 |
}; |
| 1210 |
struct C { |
| 1211 |
operator f0*(); // #cwg280-C-f0 |
| 1212 |
operator f1*(); // #cwg280-C-f1 |
| 1213 |
operator f2*(); // #cwg280-C-f2 |
| 1214 |
operator f3*(); // #cwg280-C-f3 |
| 1215 |
}; |
| 1216 |
struct D : private A, B { // #cwg280-D |
| 1217 |
operator f2*(); // #cwg280-D-f2 |
| 1218 |
} d; |
| 1219 |
struct E : C, D {} e; |
| 1220 |
void g() { |
| 1221 |
d(); // ok, public |
| 1222 |
d(0); |
| 1223 |
// expected-error@-1 {{'operator void (*)(int)' is a private member of 'cwg280::A'}} |
| 1224 |
// expected-note@#cwg280-D {{constrained by private inheritance here}} |
| 1225 |
// expected-note@#cwg280-A-f1 {{member is declared here}} |
| 1226 |
d(0, 0); // ok, suppressed by member in D |
| 1227 |
d(0, 0, 0); |
| 1228 |
// expected-error@-1 {{'operator void (*)(int, int, int)' is a private member of 'cwg280::B'}} |
| 1229 |
// expected-note@#cwg280-B-f3 {{declared private here}} |
| 1230 |
e(); |
| 1231 |
// expected-error@-1 {{call to object of type 'struct E' is ambiguous}} |
| 1232 |
// expected-note@#cwg280-B-f0 {{conversion candidate of type 'void (*)()'}} |
| 1233 |
// expected-note@#cwg280-C-f0 {{conversion candidate of type 'void (*)()'}} |
| 1234 |
e(0); |
| 1235 |
// expected-error@-1 {{call to object of type 'struct E' is ambiguous}} |
| 1236 |
// expected-note@#cwg280-A-f1 {{conversion candidate of type 'void (*)(int)'}} |
| 1237 |
// expected-note@#cwg280-C-f1 {{conversion candidate of type 'void (*)(int)'}} |
| 1238 |
e(0, 0); |
| 1239 |
// expected-error@-1 {{call to object of type 'struct E' is ambiguous}} |
| 1240 |
// expected-note@#cwg280-C-f2 {{conversion candidate of type 'void (*)(int, int)'}} |
| 1241 |
// expected-note@#cwg280-D-f2 {{conversion candidate of type 'void (*)(int, int)'}} |
| 1242 |
e(0, 0, 0); |
| 1243 |
// expected-error@-1 {{call to object of type 'struct E' is ambiguous}} |
| 1244 |
// expected-note@#cwg280-B-f3 {{conversion candidate of type 'void (*)(int, int, int)'}} |
| 1245 |
// expected-note@#cwg280-C-f3 {{conversion candidate of type 'void (*)(int, int, int)'}} |
| 1246 |
} |
| 1247 |
} // namespace cwg280 |
| 1248 |
|
| 1249 |
namespace cwg281 { // cwg281: no |
| 1250 |
void a(); |
| 1251 |
inline void b(); |
| 1252 |
|
| 1253 |
void d(); |
| 1254 |
inline void e(); |
| 1255 |
|
| 1256 |
struct S { |
| 1257 |
friend inline void a(); // FIXME: ill-formed |
| 1258 |
friend inline void b(); |
| 1259 |
friend inline void c(); // FIXME: ill-formed |
| 1260 |
friend inline void d() {} |
| 1261 |
friend inline void e() {} |
| 1262 |
friend inline void f() {} |
| 1263 |
}; |
| 1264 |
} // namespace cwg281 |
| 1265 |
|
| 1266 |
namespace cwg283 { // cwg283: 2.7 |
| 1267 |
template<typename T> // #cwg283-template |
| 1268 |
struct S { |
| 1269 |
friend class T; |
| 1270 |
// expected-error@-1 {{declaration of 'T' shadows template parameter}} |
| 1271 |
// expected-note@#cwg283-template {{template parameter is declared here}} |
| 1272 |
class T; |
| 1273 |
// expected-error@-1 {{declaration of 'T' shadows template parameter}} |
| 1274 |
// expected-note@#cwg283-template {{template parameter is declared here}} |
| 1275 |
}; |
| 1276 |
} // namespace cwg283 |
| 1277 |
|
| 1278 |
namespace cwg284 { // cwg284: no |
| 1279 |
namespace A { |
| 1280 |
struct X; |
| 1281 |
enum Y {}; |
| 1282 |
class Z {}; |
| 1283 |
} |
| 1284 |
namespace B { |
| 1285 |
struct W; |
| 1286 |
using A::X; |
| 1287 |
using A::Y; |
| 1288 |
using A::Z; |
| 1289 |
} |
| 1290 |
struct B::V {}; |
| 1291 |
// expected-error@-1 {{no struct named 'V' in namespace 'cwg284::B'}} |
| 1292 |
struct B::W {}; |
| 1293 |
struct B::X {}; // FIXME: ill-formed |
| 1294 |
enum B::Y e; // ok per cwg417 |
| 1295 |
class B::Z z; // ok per cwg417 |
| 1296 |
|
| 1297 |
struct C { |
| 1298 |
struct X; |
| 1299 |
enum Y {}; |
| 1300 |
class Z {}; |
| 1301 |
}; |
| 1302 |
struct D : C { |
| 1303 |
struct W; |
| 1304 |
using C::X; |
| 1305 |
using C::Y; |
| 1306 |
using C::Z; |
| 1307 |
}; |
| 1308 |
struct D::V {}; |
| 1309 |
// expected-error@-1 {{no struct named 'V' in 'cwg284::D'}} |
| 1310 |
struct D::W {}; |
| 1311 |
struct D::X {}; // FIXME: ill-formed |
| 1312 |
enum D::Y e2; // ok per cwg417 |
| 1313 |
class D::Z z2; // ok per cwg417 |
| 1314 |
} // namespace cwg284 |
| 1315 |
|
| 1316 |
namespace cwg285 { // cwg285: 2.7 |
| 1317 |
template<typename T> void f(T, int); // #cwg285-f-T-int |
| 1318 |
template<typename T> void f(int, T); // #cwg285-f-int-T |
| 1319 |
template<> void f<int>(int, int) {} |
| 1320 |
// expected-error@-1 {{function template specialization 'f' ambiguously refers to more than one function template; explicitly specify additional template arguments to identify a particular function template}} |
| 1321 |
// expected-note@#cwg285-f-int-T {{function template 'cwg285::f<int>' matches specialization [with T = int]}} |
| 1322 |
// expected-note@#cwg285-f-T-int {{function template 'cwg285::f<int>' matches specialization [with T = int]}} |
| 1323 |
} // namespace cwg285 |
| 1324 |
|
| 1325 |
namespace cwg286 { // cwg286: 2.8 |
| 1326 |
template<class T> struct A { |
| 1327 |
class C { |
| 1328 |
template<class T2> struct B {}; // #cwg286-B |
| 1329 |
}; |
| 1330 |
}; |
| 1331 |
|
| 1332 |
template<class T> |
| 1333 |
template<class T2> |
| 1334 |
struct A<T>::C::B<T2*> { }; |
| 1335 |
|
| 1336 |
A<short>::C::B<int*> absip; |
| 1337 |
// expected-error@-1 {{'B' is a private member of 'cwg286::A<short>::C'}} |
| 1338 |
// expected-note@#cwg286-B {{implicitly declared private here}} |
| 1339 |
} // namespace cwg286 |
| 1340 |
|
| 1341 |
// cwg288: na |
| 1342 |
|
| 1343 |
namespace cwg289 { // cwg289: 2.7 |
| 1344 |
struct A; // #cwg289-A |
| 1345 |
struct B : A {}; |
| 1346 |
// expected-error@-1 {{base class has incomplete type}} |
| 1347 |
// expected-note@#cwg289-A {{forward declaration of 'cwg289::A'}} |
| 1348 |
|
| 1349 |
template<typename T> struct C { typename T::error error; }; |
| 1350 |
// expected-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}} |
| 1351 |
// expected-note@#cwg289-C-int {{in instantiation of template class 'cwg289::C<int>' requested here}} |
| 1352 |
struct D : C<int> {}; // #cwg289-C-int |
| 1353 |
} // namespace cwg289 |
| 1354 |
|
| 1355 |
// cwg290: na |
| 1356 |
// cwg291: dup 391 |
| 1357 |
// cwg292 is in cwg292.cpp |
| 1358 |
|
| 1359 |
namespace cwg294 { // cwg294: no |
| 1360 |
void f() throw(int); |
| 1361 |
// since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}} |
| 1362 |
// since-cxx17-note@-2 {{use 'noexcept(false)' instead}} |
| 1363 |
int main() { |
| 1364 |
(void)static_cast<void (*)() throw()>(f); // FIXME: ill-formed in C++14 and before |
| 1365 |
// FIXME: since-cxx17-error@-1 {{static_cast from 'void (*)() throw(int)' to 'void (*)() throw()' is not allowed}} |
| 1366 |
// |
| 1367 |
// Irony: the above is valid in C++17 and beyond, but that's exactly when |
| 1368 |
// we reject it. In C++14 and before, this is ill-formed because an |
| 1369 |
// exception-specification is not permitted in a type-id. In C++17, this is |
| 1370 |
// valid because it's the inverse of a standard conversion sequence |
| 1371 |
// containing a function pointer conversion. (Well, it's actually not valid |
| 1372 |
// yet, as a static_cast is not permitted to reverse a function pointer |
| 1373 |
// conversion, but that is being changed by core issue). |
| 1374 |
(void)static_cast<void (*)() throw(int)>(f); // FIXME: ill-formed in C++14 and before |
| 1375 |
// since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}} |
| 1376 |
// since-cxx17-note@-2 {{use 'noexcept(false)' instead}} |
| 1377 |
|
| 1378 |
void (*p)() throw() = f; |
| 1379 |
// cxx98-14-error@-1 {{target exception specification is not superset of source}} |
| 1380 |
// since-cxx17-error@-2 {{cannot initialize a variable of type 'void (*)() throw()' with an lvalue of type 'void () throw(int)': different exception specifications}} |
| 1381 |
void (*q)() throw(int) = f; |
| 1382 |
// since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}} |
| 1383 |
// since-cxx17-note@-2 {{use 'noexcept(false)' instead}} |
| 1384 |
} |
| 1385 |
} // namespace cwg294 |
| 1386 |
|
| 1387 |
namespace cwg295 { // cwg295: 3.7 |
| 1388 |
typedef int f(); |
| 1389 |
const f g; |
| 1390 |
// expected-warning@-1 {{'const' qualifier on function type 'f' (aka 'int ()') has no effect}} |
| 1391 |
f &r = g; |
| 1392 |
template<typename T> struct X { |
| 1393 |
const T &f; |
| 1394 |
}; |
| 1395 |
X<f> x = {g}; |
| 1396 |
|
| 1397 |
typedef int U(); |
| 1398 |
typedef const U U; |
| 1399 |
// expected-warning@-1 {{'const' qualifier on function type 'U' (aka 'int ()') has no effect}} |
| 1400 |
|
| 1401 |
typedef int (*V)(); |
| 1402 |
typedef volatile U *V; |
| 1403 |
// expected-warning@-1 {{'volatile' qualifier on function type 'U' (aka 'int ()') has no effect}} |
| 1404 |
} // namespace cwg295 |
| 1405 |
|
| 1406 |
namespace cwg296 { // cwg296: 2.7 |
| 1407 |
struct A { |
| 1408 |
static operator int() { return 0; } |
| 1409 |
// expected-error@-1 {{conversion function must be a non-static member function}} |
| 1410 |
}; |
| 1411 |
} // namespace cwg296 |
| 1412 |
|
| 1413 |
namespace cwg298 { // cwg298: 3.1 |
| 1414 |
struct A { |
| 1415 |
typedef int type; |
| 1416 |
A(); |
| 1417 |
~A(); |
| 1418 |
}; |
| 1419 |
typedef A B; // #cwg298-B |
| 1420 |
typedef const A C; // #cwg298-C |
| 1421 |
|
| 1422 |
A::type i1; |
| 1423 |
B::type i2; |
| 1424 |
C::type i3; |
| 1425 |
|
| 1426 |
struct A a; |
| 1427 |
struct B b; |
| 1428 |
// expected-error@-1 {{typedef 'B' cannot be referenced with the 'struct' specifier}} |
| 1429 |
// expected-note@#cwg298-B {{declared here}} |
| 1430 |
struct C c; |
| 1431 |
// expected-error@-1 {{typedef 'C' cannot be referenced with the 'struct' specifier}} |
| 1432 |
// expected-note@#cwg298-C {{declared here}} |
| 1433 |
|
| 1434 |
B::B() {} |
| 1435 |
// expected-error@-1 {{a type specifier is required for all declarations}} |
| 1436 |
B::A() {} // ok |
| 1437 |
C::~C() {} |
| 1438 |
// expected-error@-1 {{destructor cannot be declared using a typedef 'C' (aka 'const A') of the class name}} |
| 1439 |
|
| 1440 |
typedef struct D E; // #cwg298-E |
| 1441 |
struct E {}; |
| 1442 |
// expected-error@-1 {{definition of type 'E' conflicts with typedef of the same name}} |
| 1443 |
// expected-note@#cwg298-E {{'E' declared here}} |
| 1444 |
|
| 1445 |
struct F { |
| 1446 |
~F(); |
| 1447 |
}; |
| 1448 |
typedef const F G; |
| 1449 |
G::~F() {} // ok |
| 1450 |
} // namespace cwg298 |
| 1451 |
|
| 1452 |
namespace cwg299 { // cwg299: 2.8 c++11 |
| 1453 |
struct S { |
| 1454 |
operator int(); |
| 1455 |
}; |
| 1456 |
struct T { |
| 1457 |
operator int(); // #cwg299-int |
| 1458 |
operator unsigned short(); // #cwg299-ushort |
| 1459 |
}; |
| 1460 |
// FIXME: should this apply to c++98 mode? |
| 1461 |
int *p = new int[S()]; |
| 1462 |
// cxx98-error@-1 {{implicit conversion from array size expression of type 'S' to integral type 'int' is a C++11 extension}} |
| 1463 |
int *q = new int[T()]; // #cwg299-q |
| 1464 |
// cxx98-11-error@#cwg299-q {{ambiguous conversion of array size expression of type 'T' to an integral or enumeration type}} |
| 1465 |
// cxx98-11-note@#cwg299-int {{conversion to integral type 'int' declared here}} |
| 1466 |
// cxx98-11-note@#cwg299-ushort {{conversion to integral type 'unsigned short' declared here}} |
| 1467 |
// since-cxx14-error-re@#cwg299-q {{conversion from 'T' to '__size_t' (aka 'unsigned {{long long|long|int}}') is ambiguous}} |
| 1468 |
// since-cxx14-note@#cwg299-int {{candidate function}} |
| 1469 |
// since-cxx14-note@#cwg299-ushort {{candidate function}} |
| 1470 |
} // namespace cwg299 |