| 1 |
// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++98 %s -verify=expected,cxx98-14,cxx98-17,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors |
| 2 |
// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++11 %s -verify=expected,cxx98-14,cxx98-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors |
| 3 |
// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++14 %s -verify=expected,cxx98-14,cxx98-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors |
| 4 |
// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++17 %s -verify=expected,since-cxx17,cxx98-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors |
| 5 |
// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++20 %s -verify=expected,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors |
| 6 |
// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++23 %s -verify=expected,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors |
| 7 |
// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++2c %s -verify=expected,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors |
| 8 |
|
| 9 |
#if __cplusplus == 199711L |
| 10 |
#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__) |
| 11 |
// cxx98-error@-1 {{variadic macros are a C99 feature}} |
| 12 |
#endif |
| 13 |
|
| 14 |
// FIXME: __SIZE_TYPE__ expands to 'long long' on some targets. |
| 15 |
__extension__ typedef __SIZE_TYPE__ size_t; |
| 16 |
|
| 17 |
namespace std { struct type_info; } |
| 18 |
|
| 19 |
namespace cwg400 { // cwg400: 2.7 |
| 20 |
struct A { int a; struct a {}; }; // #cwg400-A |
| 21 |
struct B { int a; struct a {}; }; // #cwg400-B |
| 22 |
struct C : A, B { using A::a; struct a b; }; |
| 23 |
struct D : A, B { |
| 24 |
using A::a; |
| 25 |
// FIXME: we should issue a single diagnostic |
| 26 |
using B::a; // #cwg400-using-B-a |
| 27 |
// expected-error@#cwg400-using-B-a {{target of using declaration conflicts with declaration already in scope}} |
| 28 |
// expected-note@#cwg400-B {{target of using declaration}} |
| 29 |
// expected-note@#cwg400-A {{conflicting declaration}} |
| 30 |
// expected-error@#cwg400-using-B-a {{target of using declaration conflicts with declaration already in scope}} |
| 31 |
// expected-note@#cwg400-B {{target of using declaration}} |
| 32 |
// expected-note@#cwg400-A {{conflicting declaration}} |
| 33 |
struct a b; |
| 34 |
}; |
| 35 |
struct E : A, B { struct a b; }; |
| 36 |
// expected-error@-1 {{member 'a' found in multiple base classes of different types}} |
| 37 |
// expected-note@#cwg400-A {{member type 'cwg400::A::a' found by ambiguous name lookup}} |
| 38 |
// expected-note@#cwg400-B {{member type 'cwg400::B::a' found by ambiguous name lookup}} |
| 39 |
struct F : A {}; |
| 40 |
struct G : A { |
| 41 |
using G::A; |
| 42 |
// expected-error@-1 {{using declaration refers to its own class}} |
| 43 |
using G::a; |
| 44 |
// expected-error@-1 {{using declaration refers to its own class}} |
| 45 |
using F::a; |
| 46 |
// expected-error@-1 {{using declaration refers into 'F', which is not a base class of 'G'}} |
| 47 |
}; |
| 48 |
} // namespace cwg400 |
| 49 |
|
| 50 |
namespace cwg401 { // cwg401: 2.8 |
| 51 |
template<class T, class U = typename T::type> class A : public T {}; // #cwg401-A |
| 52 |
// expected-error@#cwg401-A {{'type' is a private member of 'cwg401::C'}} |
| 53 |
// expected-note@#cwg402-friend-A-C {{in instantiation of default argument for 'A<C>' required here}} |
| 54 |
// expected-note@#cwg402-C-type {{implicitly declared private here}} |
| 55 |
// expected-error@#cwg401-A {{'type' is a protected member of 'cwg401::B'}} |
| 56 |
// expected-note@#cwg402-b {{in instantiation of default argument for 'A<B>' required here}} |
| 57 |
// expected-note@#cwg402-B-type {{declared protected here}} |
| 58 |
// expected-error@#cwg401-A {{'type' is a private member of 'cwg401::D'}} |
| 59 |
// expected-note@#cwg402-d {{in instantiation of default argument for 'A<D>' required here}} |
| 60 |
// expected-note@#cwg402-D-type {{implicitly declared private here}} |
| 61 |
class B { |
| 62 |
protected: |
| 63 |
typedef int type; // #cwg402-B-type |
| 64 |
}; |
| 65 |
|
| 66 |
class C { |
| 67 |
typedef int type; // #cwg402-C-type |
| 68 |
friend class A<C>; // #cwg402-friend-A-C |
| 69 |
}; |
| 70 |
|
| 71 |
class D { |
| 72 |
typedef int type; // #cwg402-D-type |
| 73 |
friend class A<D, int>; |
| 74 |
}; |
| 75 |
|
| 76 |
A<B> *b; // #cwg402-b |
| 77 |
A<D> *d; // #cwg402-d |
| 78 |
|
| 79 |
struct E { |
| 80 |
template<class T, class U = typename T::type> class A : public T {}; |
| 81 |
}; |
| 82 |
class F { |
| 83 |
typedef int type; |
| 84 |
friend class E; |
| 85 |
}; |
| 86 |
E::A<F> eaf; // ok, default argument is in befriended context |
| 87 |
|
| 88 |
// FIXME: Why do we get different diagnostics in C++11 onwards here? We seem |
| 89 |
// to not treat the default template argument as a SFINAE context in C++98. |
| 90 |
template<class T, class U = typename T::type> void f(T) {} // #cwg402-f |
| 91 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 92 |
// cxx98-error@-2 {{'type' is a protected member of 'cwg401::B'}} |
| 93 |
// cxx98-note@-3 {{in instantiation of default argument for 'f<B>' required here}} |
| 94 |
// cxx98-note@#cwg402-f-b {{while substituting deduced template arguments into function template 'f' [with T = B, U = (no value)]}} |
| 95 |
// cxx98-note@#cwg402-B-type {{declared protected here}} |
| 96 |
void g(B b) { f(b); } // #cwg402-f-b |
| 97 |
// since-cxx11-error@-1 {{no matching function for call to 'f'}} |
| 98 |
// since-cxx11-note@#cwg402-f {{candidate template ignored: substitution failure [with T = B, U = typename B::type]: 'type' is a protected member of 'cwg401::B'}} |
| 99 |
} // namespace cwg401 |
| 100 |
|
| 101 |
namespace cwg403 { // cwg403: 2.7 |
| 102 |
namespace A { |
| 103 |
struct S {}; |
| 104 |
int f(void*); |
| 105 |
} |
| 106 |
template<typename T> struct X {}; |
| 107 |
typedef struct X<A::S>::X XS; |
| 108 |
XS *p; |
| 109 |
int k = f(p); // ok, finds A::f, even though type XS is a typedef-name |
| 110 |
// referring to an elaborated-type-specifier naming a |
| 111 |
// injected-class-name, which is about as far from a |
| 112 |
// template-id as we can make it. |
| 113 |
} // namespace cwg403 |
| 114 |
|
| 115 |
// cwg404: na |
| 116 |
// (NB: also sup 594) |
| 117 |
|
| 118 |
namespace cwg405 { // cwg405: 2.7 |
| 119 |
// NB: also dup 218 |
| 120 |
namespace A { |
| 121 |
struct S {}; |
| 122 |
void f(S); |
| 123 |
} |
| 124 |
namespace B { |
| 125 |
struct S {}; |
| 126 |
void f(S); |
| 127 |
} |
| 128 |
|
| 129 |
struct C { |
| 130 |
int f; |
| 131 |
void test1(A::S as) { f(as); } |
| 132 |
// expected-error@-1 {{called object type 'int' is not a function or function pointer}} |
| 133 |
void test2(A::S as) { void f(); f(as); } |
| 134 |
// expected-error@-1 {{too many arguments to function call, expected 0, have 1}} |
| 135 |
// expected-note@-2 {{'f' declared here}} |
| 136 |
void test3(A::S as) { using A::f; f(as); } // ok |
| 137 |
void test4(A::S as) { using B::f; f(as); } // ok |
| 138 |
void test5(A::S as) { int f; f(as); } |
| 139 |
// expected-error@-1 {{called object type 'int' is not a function or function pointer}} |
| 140 |
void test6(A::S as) { struct f {}; (void) f(as); } |
| 141 |
// expected-error@-1 {{no matching conversion for functional-style cast from 'A::S' to 'f'}} |
| 142 |
// expected-note@-2 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A::S' to 'const f' for 1st argument}} |
| 143 |
// since-cxx11-note@-3 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A::S' to 'f' for 1st argument}} |
| 144 |
// expected-note@-4 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}} |
| 145 |
}; |
| 146 |
|
| 147 |
namespace D { |
| 148 |
struct S {}; |
| 149 |
struct X { void operator()(S); } f; |
| 150 |
} |
| 151 |
void testD(D::S ds) { f(ds); } |
| 152 |
// expected-error@-1 {{use of undeclared identifier 'f'}} |
| 153 |
|
| 154 |
namespace E { |
| 155 |
struct S {}; |
| 156 |
struct f { f(S); }; |
| 157 |
} |
| 158 |
void testE(E::S es) { f(es); } |
| 159 |
// expected-error@-1 {{use of undeclared identifier 'f'}} |
| 160 |
} // namespace cwg405 |
| 161 |
|
| 162 |
namespace cwg406 { // cwg406: 2.9 |
| 163 |
typedef struct { |
| 164 |
static int n; |
| 165 |
// expected-error@-1 {{static data member 'n' not allowed in anonymous struct}} |
| 166 |
} A; |
| 167 |
typedef union { |
| 168 |
static int n; |
| 169 |
// expected-error@-1 {{static data member 'n' not allowed in anonymous union}} |
| 170 |
} B; |
| 171 |
} // namespace cwg406 |
| 172 |
|
| 173 |
namespace cwg407 { // cwg407: 3.8 |
| 174 |
// NB: reused by cwg1894 and cwg2199 |
| 175 |
struct S; |
| 176 |
typedef struct S S; |
| 177 |
void f() { |
| 178 |
struct S *p; |
| 179 |
{ |
| 180 |
typedef struct S S; // #cwg407-typedef-S |
| 181 |
struct S *p; |
| 182 |
// expected-error@-1 {{typedef 'S' cannot be referenced with the 'struct' specifier}} |
| 183 |
// expected-note@#cwg407-typedef-S {{declared here}} |
| 184 |
} |
| 185 |
} |
| 186 |
struct S {}; |
| 187 |
|
| 188 |
namespace UsingDir { |
| 189 |
namespace A { |
| 190 |
struct S {}; // #cwg407-A-S |
| 191 |
} |
| 192 |
namespace B { |
| 193 |
typedef int S; // #cwg407-B-S |
| 194 |
} |
| 195 |
namespace C { |
| 196 |
using namespace A; |
| 197 |
using namespace B; |
| 198 |
struct S s; |
| 199 |
// expected-error@-1 {{ambiguous}} |
| 200 |
// expected-note@#cwg407-A-S {{candidate found by name lookup is 'cwg407::UsingDir::A::S'}} |
| 201 |
// expected-note@#cwg407-B-S {{candidate found by name lookup is 'cwg407::UsingDir::B::S'}} |
| 202 |
} |
| 203 |
namespace D { |
| 204 |
using A::S; |
| 205 |
typedef struct S S; |
| 206 |
struct S s; |
| 207 |
} |
| 208 |
namespace E { |
| 209 |
// The standard doesn't say whether this is valid. We interpret |
| 210 |
// CWG407 as meaning "if lookup finds both a tag and a typedef with the |
| 211 |
// same type, then it's OK in an elaborated-type-specifier". |
| 212 |
typedef A::S S; |
| 213 |
using A::S; |
| 214 |
struct S s; |
| 215 |
} |
| 216 |
namespace F { |
| 217 |
typedef A::S S; |
| 218 |
} |
| 219 |
// The standard doesn't say what to do in these cases either. |
| 220 |
namespace G { |
| 221 |
using namespace A; |
| 222 |
using namespace F; |
| 223 |
struct S s; |
| 224 |
} |
| 225 |
namespace H { |
| 226 |
using namespace F; |
| 227 |
using namespace A; |
| 228 |
struct S s; |
| 229 |
} |
| 230 |
} |
| 231 |
} // namespace cwg407 |
| 232 |
|
| 233 |
namespace cwg408 { // cwg408: 3.4 |
| 234 |
template<int N> void g() { static_assert(N != 1, ""); } |
| 235 |
template<> void g<2>() { } |
| 236 |
|
| 237 |
template<typename T> struct S { |
| 238 |
static int i[]; |
| 239 |
void f(); |
| 240 |
}; |
| 241 |
template<typename T> int S<T>::i[] = { 1 }; |
| 242 |
|
| 243 |
template<typename T> void S<T>::f() { |
| 244 |
g<sizeof (i) / sizeof (int)>(); |
| 245 |
} |
| 246 |
template<> int S<int>::i[] = { 1, 2 }; |
| 247 |
template void S<int>::f(); // uses g<2>(), not g<1>(). |
| 248 |
|
| 249 |
|
| 250 |
template<typename T> struct R { |
| 251 |
static int arr[]; |
| 252 |
void f(); |
| 253 |
}; |
| 254 |
template<typename T> int R<T>::arr[1]; |
| 255 |
template<typename T> void R<T>::f() { |
| 256 |
static_assert(sizeof(arr) != sizeof(int), ""); |
| 257 |
} |
| 258 |
template<> int R<int>::arr[2]; |
| 259 |
template void R<int>::f(); |
| 260 |
} // namespace cwg408 |
| 261 |
|
| 262 |
namespace cwg409 { // cwg409: 2.7 |
| 263 |
template<typename T> struct A { |
| 264 |
typedef int B; |
| 265 |
B b1; |
| 266 |
A::B b2; |
| 267 |
A<T>::B b3; |
| 268 |
A<T*>::B b4; |
| 269 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'A<T *>::B' is a C++20 extension}} |
| 270 |
}; |
| 271 |
} // namespace cwg409 |
| 272 |
|
| 273 |
namespace cwg410 { // cwg410: no |
| 274 |
template<class T> void f(T); |
| 275 |
void g(int); |
| 276 |
namespace M { |
| 277 |
template<class T> void h(T); |
| 278 |
template<class T> void i(T); |
| 279 |
struct A { |
| 280 |
friend void f<>(int); |
| 281 |
friend void h<>(int); |
| 282 |
friend void g(int); |
| 283 |
template<class T> void i(T); |
| 284 |
friend void i<>(int); |
| 285 |
private: |
| 286 |
static void z(); // #cwg410-z |
| 287 |
}; |
| 288 |
|
| 289 |
template<> void h(int) { A::z(); } |
| 290 |
// FIXME: This should be ill-formed. The member A::i<> is befriended, |
| 291 |
// not this function. |
| 292 |
template<> void i(int) { A::z(); } |
| 293 |
} |
| 294 |
template<> void f(int) { M::A::z(); } |
| 295 |
void g(int) { M::A::z(); } |
| 296 |
// expected-error@-1 {{'z' is a private member of 'cwg410::M::A'}} |
| 297 |
// expected-note@#cwg410-z {{declared private here}} |
| 298 |
} // namespace cwg410 |
| 299 |
|
| 300 |
// cwg412 is in cwg412.cpp |
| 301 |
|
| 302 |
namespace cwg413 { // cwg413: 2.7 |
| 303 |
struct S { |
| 304 |
int a; |
| 305 |
int : 17; |
| 306 |
int b; |
| 307 |
}; |
| 308 |
S s = { 1, 2, 3 }; |
| 309 |
// expected-error@-1 {{excess elements in struct initializer}} |
| 310 |
|
| 311 |
struct E {}; |
| 312 |
struct T { // #cwg413-T |
| 313 |
int a; |
| 314 |
E e; |
| 315 |
int b; |
| 316 |
}; |
| 317 |
T t1 = { 1, {}, 2 }; |
| 318 |
T t2 = { 1, 2 }; |
| 319 |
// expected-error@-1 {{initializer for aggregate with no elements requires explicit braces}} |
| 320 |
// expected-note@#cwg413-T {{'cwg413::T' declared here}} |
| 321 |
} // namespace cwg413 |
| 322 |
|
| 323 |
namespace cwg414 { // cwg414: dup 305 |
| 324 |
struct X {}; |
| 325 |
void f() { |
| 326 |
X x; |
| 327 |
struct X {}; |
| 328 |
x.~X(); |
| 329 |
} |
| 330 |
} // namespace cwg414 |
| 331 |
|
| 332 |
namespace cwg415 { // cwg415: 2.7 |
| 333 |
template<typename T> void f(T, ...) { T::error; } |
| 334 |
void f(int, int); |
| 335 |
void g() { f(0, 0); } // ok |
| 336 |
} // namespace cwg415 |
| 337 |
|
| 338 |
namespace cwg416 { // cwg416: 2.7 |
| 339 |
extern struct A a; |
| 340 |
int &operator+(const A&, const A&); |
| 341 |
int &k = a + a; |
| 342 |
struct A { float &operator+(A&); }; |
| 343 |
float &f = a + a; |
| 344 |
} // namespace cwg416 |
| 345 |
|
| 346 |
namespace cwg417 { // cwg417: no |
| 347 |
struct A; |
| 348 |
struct cwg417::A {}; |
| 349 |
// expected-warning@-1 {{extra qualification on member 'A'}} |
| 350 |
struct B { struct X; }; |
| 351 |
struct C : B {}; |
| 352 |
struct C::X {}; |
| 353 |
// expected-error@-1 {{no struct named 'X' in 'cwg417::C'}} |
| 354 |
struct B::X { struct Y; }; |
| 355 |
struct C::X::Y {}; // ok! |
| 356 |
namespace N { |
| 357 |
struct D; |
| 358 |
struct E; |
| 359 |
struct F; |
| 360 |
struct H; |
| 361 |
} |
| 362 |
// FIXME: This is ill-formed. |
| 363 |
using N::D; |
| 364 |
struct cwg417::D {}; |
| 365 |
// expected-warning@-1 {{extra qualification on member 'D'}} |
| 366 |
using namespace N; |
| 367 |
struct cwg417::E {}; |
| 368 |
// expected-error@-1 {{no struct named 'E' in namespace 'cwg417'}} |
| 369 |
// expected-warning@-2 {{extra qualification on member 'E'}} |
| 370 |
struct N::F {}; |
| 371 |
struct G; |
| 372 |
using N::H; |
| 373 |
namespace M { |
| 374 |
struct cwg417::G {}; |
| 375 |
// expected-error@-1 {{cannot define or redeclare 'G' here because namespace 'M' does not enclose namespace 'cwg417'}} |
| 376 |
struct cwg417::H {}; |
| 377 |
// expected-error@-1 {{cannot define or redeclare 'H' here because namespace 'M' does not enclose namespace 'cwg417'}} |
| 378 |
} |
| 379 |
} // namespace cwg417 |
| 380 |
|
| 381 |
namespace cwg418 { // cwg418: no |
| 382 |
namespace example1 { |
| 383 |
void f1(int, int = 0); |
| 384 |
void f1(int = 0, int); |
| 385 |
|
| 386 |
void g() { f1(); } |
| 387 |
} // namespace example1 |
| 388 |
|
| 389 |
namespace example2 { |
| 390 |
namespace A { |
| 391 |
void f2(int); // #cwg418-f2 |
| 392 |
} |
| 393 |
namespace B { |
| 394 |
using A::f2; |
| 395 |
} |
| 396 |
namespace A { |
| 397 |
void f2(int = 3); |
| 398 |
} |
| 399 |
void g2() { |
| 400 |
using B::f2; |
| 401 |
f2(); |
| 402 |
// expected-error@-1 {{no matching function for call to 'f2'}} |
| 403 |
// expected-note@#cwg418-f2 {{candidate function not viable: requires 1 argument, but 0 were provided}} |
| 404 |
} |
| 405 |
} // namespace example2 |
| 406 |
|
| 407 |
// example from [over.match.best]/4 |
| 408 |
namespace example3 { |
| 409 |
namespace A { |
| 410 |
extern "C" void f(int = 5); |
| 411 |
} |
| 412 |
namespace B { |
| 413 |
extern "C" void f(int = 5); |
| 414 |
} |
| 415 |
|
| 416 |
using A::f; |
| 417 |
using B::f; |
| 418 |
|
| 419 |
void use() { |
| 420 |
f(3); |
| 421 |
f(); // FIXME: this should fail |
| 422 |
} |
| 423 |
} // namespace example3 |
| 424 |
} // namespace cwg418 |
| 425 |
|
| 426 |
namespace cwg420 { // cwg420: 9 |
| 427 |
template<typename T> struct ptr { |
| 428 |
T *operator->() const; |
| 429 |
T &operator*() const; |
| 430 |
}; |
| 431 |
template<typename T, typename P> void test(P p) { |
| 432 |
p->~T(); |
| 433 |
p->T::~T(); |
| 434 |
(*p).~T(); |
| 435 |
(*p).T::~T(); |
| 436 |
} |
| 437 |
struct X {}; |
| 438 |
template void test<int>(int*); |
| 439 |
template void test<int>(ptr<int>); |
| 440 |
template void test<X>(X*); |
| 441 |
template void test<X>(ptr<X>); |
| 442 |
|
| 443 |
template<typename T> |
| 444 |
void test2(T p) { |
| 445 |
p->template Y<int>::~Y<int>(); |
| 446 |
p->~Y<int>(); |
| 447 |
p->template ~Y<int>(); |
| 448 |
// expected-error@-1 {{'template' keyword not permitted in destructor name}} |
| 449 |
} |
| 450 |
template<typename T> struct Y {}; |
| 451 |
template void test2(Y<int>*); |
| 452 |
template void test2(ptr<Y<int> >); |
| 453 |
|
| 454 |
void test3(int *p, ptr<int> q) { |
| 455 |
typedef int Int; |
| 456 |
p->~Int(); |
| 457 |
q->~Int(); |
| 458 |
p->Int::~Int(); |
| 459 |
q->Int::~Int(); |
| 460 |
} |
| 461 |
|
| 462 |
#if __cplusplus >= 201103L |
| 463 |
template<typename T> using id = T; |
| 464 |
struct A { template<typename T> using id = T; }; |
| 465 |
void test4(int *p, ptr<int> q) { |
| 466 |
p->~id<int>(); |
| 467 |
q->~id<int>(); |
| 468 |
p->id<int>::~id<int>(); |
| 469 |
q->id<int>::~id<int>(); |
| 470 |
p->template id<int>::~id<int>(); // OK since cwg2292 |
| 471 |
q->template id<int>::~id<int>(); // OK since cwg2292 |
| 472 |
p->A::template id<int>::~id<int>(); |
| 473 |
q->A::template id<int>::~id<int>(); |
| 474 |
} |
| 475 |
#endif |
| 476 |
} // namespace cwg420 |
| 477 |
|
| 478 |
namespace cwg421 { // cwg421: 2.7 |
| 479 |
struct X { X(); int n; int &r; }; |
| 480 |
int *p = &X().n; |
| 481 |
// cxx98-error@-1 {{taking the address of a temporary object of type 'int'}} |
| 482 |
// since-cxx11-error@-2 {{cannot take the address of an rvalue of type 'int'}} |
| 483 |
int *q = &X().r; |
| 484 |
} // namespace cwg421 |
| 485 |
|
| 486 |
namespace cwg422 { // cwg422: 2.7 |
| 487 |
template<typename T, typename U> void f() { |
| 488 |
typedef T type; // #cwg422-typedef-T |
| 489 |
typedef U type; |
| 490 |
// expected-error@-1 {{typedef redefinition with different types ('char' vs 'int')}} |
| 491 |
// expected-note@#cwg422-f-int-char {{in instantiation of function template specialization 'cwg422::f<int, char>' requested here}} |
| 492 |
// expected-note@#cwg422-typedef-T {{previous definition is here}} |
| 493 |
} |
| 494 |
template void f<int, int>(); |
| 495 |
template void f<int, char>(); // #cwg422-f-int-char |
| 496 |
} // namespace cwg422 |
| 497 |
|
| 498 |
namespace cwg423 { // cwg423: 2.7 |
| 499 |
template<typename T> struct X { operator T&(); }; |
| 500 |
void f(X<int> x) { x += 1; } |
| 501 |
} // namespace cwg423 |
| 502 |
|
| 503 |
namespace cwg424 { // cwg424: 2.7 |
| 504 |
struct A { |
| 505 |
typedef int N; // #cwg424-N |
| 506 |
typedef int N; |
| 507 |
// expected-error@-1 {{redefinition of 'N'}} |
| 508 |
// expected-note@#cwg424-N {{previous definition is here}} |
| 509 |
|
| 510 |
struct X; |
| 511 |
typedef X X; // #cwg424-X |
| 512 |
struct X {}; |
| 513 |
|
| 514 |
struct X *p; |
| 515 |
struct A::X *q; |
| 516 |
X *r; |
| 517 |
|
| 518 |
typedef X X; |
| 519 |
// expected-error@-1 {{redefinition of 'X'}} |
| 520 |
// expected-note@#cwg424-X {{previous definition is here}} |
| 521 |
}; |
| 522 |
struct B { |
| 523 |
typedef int M; |
| 524 |
}; |
| 525 |
struct C : B { |
| 526 |
typedef int M; // #cwg424-M |
| 527 |
typedef int M; |
| 528 |
// expected-error@-1 {{redefinition of 'M'}} |
| 529 |
// expected-note@#cwg424-M {{previous definition is here}} |
| 530 |
}; |
| 531 |
} // namespace cwg424 |
| 532 |
|
| 533 |
namespace cwg425 { // cwg425: 2.7 |
| 534 |
struct A { template<typename T> operator T() const; } a; |
| 535 |
float f = 1.0f * a; |
| 536 |
// expected-error@-1 {{use of overloaded operator '*' is ambiguous (with operand types 'float' and 'struct A')}} |
| 537 |
// expected-note@-2 +{{built-in candidate operator*}} |
| 538 |
|
| 539 |
template<typename T> struct is_float; |
| 540 |
template<> struct is_float<float> { typedef void type; }; |
| 541 |
|
| 542 |
struct B { |
| 543 |
template<typename T, typename U = typename is_float<T>::type> operator T() const; |
| 544 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 545 |
} b; |
| 546 |
float g = 1.0f * b; // ok |
| 547 |
} // namespace cwg425 |
| 548 |
|
| 549 |
namespace cwg427 { // cwg427: 2.7 |
| 550 |
struct B {}; |
| 551 |
struct D : public B { |
| 552 |
D(B &) = delete; // #cwg427-D |
| 553 |
// cxx98-error@-1 {{deleted function definitions are a C++11 extension}} |
| 554 |
}; |
| 555 |
|
| 556 |
extern D d1; |
| 557 |
B &b = d1; |
| 558 |
const D &d2 = static_cast<const D&>(b); |
| 559 |
const D &d3 = (const D&)b; |
| 560 |
const D &d4(b); |
| 561 |
// expected-error@-1 {{conversion function from 'B' to 'const D' invokes a deleted function}} |
| 562 |
// expected-note@#cwg427-D {{'D' has been explicitly marked deleted here}} |
| 563 |
} // namespace cwg427 |
| 564 |
|
| 565 |
namespace cwg428 { // cwg428: 2.7 |
| 566 |
template<typename T> T make(); |
| 567 |
extern struct X x; // #cwg428-X |
| 568 |
void f() { |
| 569 |
throw void(); |
| 570 |
// expected-error@-1 {{cannot throw object of incomplete type 'void'}} |
| 571 |
throw make<void*>(); |
| 572 |
throw make<const volatile void*>(); |
| 573 |
throw x; |
| 574 |
// expected-error@-1 {{cannot throw object of incomplete type 'struct X'}} |
| 575 |
// expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}} |
| 576 |
throw make<X&>(); |
| 577 |
// expected-error@-1 {{cannot throw object of incomplete type 'cwg428::X'}} |
| 578 |
// expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}} |
| 579 |
throw make<X*>(); |
| 580 |
// expected-error@-1 {{cannot throw pointer to object of incomplete type 'cwg428::X'}} |
| 581 |
// expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}} |
| 582 |
throw make<const volatile X&>(); |
| 583 |
// expected-error@-1 {{cannot throw object of incomplete type 'cwg428::X'}} |
| 584 |
// expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}} |
| 585 |
throw make<const volatile X*>(); |
| 586 |
// expected-error@-1 {{cannot throw pointer to object of incomplete type 'const volatile cwg428::X'}} |
| 587 |
// expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}} |
| 588 |
} |
| 589 |
} // namespace cwg428 |
| 590 |
|
| 591 |
namespace cwg429 { // cwg429: 2.8 c++11 |
| 592 |
// FIXME: This rule is obviously intended to apply to C++98 as well. |
| 593 |
struct A { |
| 594 |
static void *operator new(size_t, size_t); |
| 595 |
static void operator delete(void*, size_t); // #cwg429-delete |
| 596 |
} *a = new (0) A; |
| 597 |
// since-cxx11-error@-1 {{'new' expression with placement arguments refers to non-placement 'operator delete'}} |
| 598 |
// since-cxx11-note@#cwg429-delete {{here}} |
| 599 |
struct B { |
| 600 |
static void *operator new(size_t, size_t); |
| 601 |
static void operator delete(void*); |
| 602 |
static void operator delete(void*, size_t); |
| 603 |
} *b = new (0) B; // ok, second delete is not a non-placement deallocation function |
| 604 |
} // namespace cwg429 |
| 605 |
|
| 606 |
namespace cwg430 { // cwg430: 2.7 c++11 |
| 607 |
// resolved by n2239 |
| 608 |
// FIXME: This should apply in C++98 too. |
| 609 |
void f(int n) { |
| 610 |
int a[] = { n++, n++, n++ }; |
| 611 |
// cxx98-warning@-1 {{multiple unsequenced modifications to 'n'}} |
| 612 |
} |
| 613 |
} // namespace cwg430 |
| 614 |
|
| 615 |
namespace cwg431 { // cwg431: 2.8 |
| 616 |
struct A { |
| 617 |
template<typename T> T *get(); |
| 618 |
template<typename T> struct B { |
| 619 |
template<typename U> U *get(); |
| 620 |
}; |
| 621 |
}; |
| 622 |
|
| 623 |
template<typename T> void f(A a) { |
| 624 |
a.get<A>()->get<T>(); |
| 625 |
a.get<T>() |
| 626 |
->get<T>(); |
| 627 |
// expected-error@-1 {{use 'template' keyword to treat 'get' as a dependent template name}} |
| 628 |
a.get<T>()->template get<T>(); |
| 629 |
a.A::get<T>(); |
| 630 |
A::B<int> *b = a.get<A::B<int> >(); |
| 631 |
b->get<int>(); |
| 632 |
b->A::B<int>::get<int>(); |
| 633 |
b->A::B<int>::get<T>(); |
| 634 |
b->A::B<T>::get<int>(); |
| 635 |
// expected-error@-1 {{use 'template' keyword to treat 'get' as a dependent template name}} |
| 636 |
b->A::B<T>::template get<int>(); |
| 637 |
b->A::B<T>::get<T>(); |
| 638 |
// expected-error@-1 {{use 'template' keyword to treat 'get' as a dependent template name}} |
| 639 |
b->A::B<T>::template get<T>(); |
| 640 |
A::B<T> *c = a.get<A::B<T> >(); |
| 641 |
c->get<int>(); |
| 642 |
// expected-error@-1 {{use 'template' keyword to treat 'get' as a dependent template name}} |
| 643 |
c->template get<int>(); |
| 644 |
} |
| 645 |
} // namespace cwg431 |
| 646 |
|
| 647 |
namespace cwg432 { // cwg432: 3.0 |
| 648 |
template<typename T> struct A {}; |
| 649 |
template<typename T> struct B : A<B> {}; |
| 650 |
// expected-error@-1 {{use of class template 'B' requires template arguments}} |
| 651 |
// expected-note@-2 {{template is declared here}} |
| 652 |
template<typename T> struct C : A<C<T> > {}; |
| 653 |
#if __cplusplus >= 201103L |
| 654 |
template<typename T> struct D : decltype(A<D>()) {}; |
| 655 |
// since-cxx11-error@-1 {{use of class template 'D' requires template arguments}} |
| 656 |
// since-cxx11-note@-2 {{template is declared here}} |
| 657 |
#endif |
| 658 |
} // namespace cwg432 |
| 659 |
|
| 660 |
namespace cwg433 { // cwg433: 2.7 |
| 661 |
template<class T> struct S { |
| 662 |
void f(union U*); |
| 663 |
}; |
| 664 |
U *p; |
| 665 |
template<class T> void S<T>::f(union U*) {} |
| 666 |
|
| 667 |
S<int> s; |
| 668 |
} // namespace cwg433 |
| 669 |
|
| 670 |
namespace cwg434 { // cwg434: sup 2352 |
| 671 |
void f() { |
| 672 |
const int ci = 0; |
| 673 |
int *pi = 0; |
| 674 |
const int *&rpci = pi; |
| 675 |
// expected-error@-1 {{binding reference of type 'const int *' to value of type 'int *' not permitted due to incompatible qualifiers}} |
| 676 |
const int * const &rcpci = pi; // OK |
| 677 |
rpci = &ci; |
| 678 |
*pi = 1; |
| 679 |
} |
| 680 |
|
| 681 |
#if __cplusplus >= 201103L |
| 682 |
int *pi = 0; |
| 683 |
const int * const &rcpci = pi; |
| 684 |
static_assert(&rcpci == &pi, ""); |
| 685 |
#endif |
| 686 |
} // namespace cwg434 |
| 687 |
|
| 688 |
// cwg435: na |
| 689 |
|
| 690 |
namespace cwg436 { // cwg436: 2.7 |
| 691 |
enum E { f }; // #cwg436-f |
| 692 |
void f(); |
| 693 |
// expected-error@-1 {{redefinition of 'f' as different kind of symbol}} |
| 694 |
// expected-note@#cwg436-f {{previous definition is here}} |
| 695 |
} // namespace cwg436 |
| 696 |
|
| 697 |
namespace cwg437 { // cwg437: sup 1308 |
| 698 |
// This is superseded by 1308, which is in turn superseded by 1330, |
| 699 |
// which restores this rule. |
| 700 |
template<typename U> struct T : U {}; |
| 701 |
struct S { |
| 702 |
void f() throw(S); |
| 703 |
// since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}} |
| 704 |
// since-cxx17-note@-2 {{use 'noexcept(false)' instead}} |
| 705 |
void g() throw(T<S>); |
| 706 |
// since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}} |
| 707 |
// since-cxx17-note@-2 {{use 'noexcept(false)' instead}} |
| 708 |
struct U; |
| 709 |
void h() throw(U); |
| 710 |
// since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}} |
| 711 |
// since-cxx17-note@-2 {{use 'noexcept(false)' instead}} |
| 712 |
struct U {}; |
| 713 |
}; |
| 714 |
} // namespace cwg437 |
| 715 |
|
| 716 |
// cwg438 is in cwg438.cpp |
| 717 |
// cwg439 is in cwg439.cpp |
| 718 |
// cwg441 is in cwg441.cpp |
| 719 |
// cwg442: sup 348 |
| 720 |
// cwg443: na |
| 721 |
|
| 722 |
namespace cwg444 { // cwg444: 2.7 |
| 723 |
struct D; |
| 724 |
struct B { // #cwg444-B |
| 725 |
D &operator=(D &) = delete; // #cwg444-deleted |
| 726 |
// cxx98-error@-1 {{deleted function definitions are a C++11 extension}} |
| 727 |
}; |
| 728 |
struct D : B { // #cwg444-D |
| 729 |
using B::operator=; |
| 730 |
} extern d; |
| 731 |
void f() { |
| 732 |
d = d; |
| 733 |
// expected-error@-1 {{overload resolution selected deleted operator '='}} |
| 734 |
// expected-note@#cwg444-deleted {{candidate function has been explicitly deleted}} |
| 735 |
// expected-note@#cwg444-D {{candidate function (the implicit copy assignment operator)}} |
| 736 |
// expected-note@#cwg444-B {{candidate function (the implicit copy assignment operator)}} |
| 737 |
// since-cxx11-note@#cwg444-B {{candidate function (the implicit move assignment operator) not viable: expects an rvalue for 1st argument}} |
| 738 |
// since-cxx11-note@#cwg444-D {{candidate function (the implicit move assignment operator) not viable: expects an rvalue for 1st argument}} |
| 739 |
} |
| 740 |
} // namespace cwg444 |
| 741 |
|
| 742 |
namespace cwg445 { // cwg445: 3.2 |
| 743 |
class A { void f(); }; // #cwg445-f |
| 744 |
struct B { |
| 745 |
friend void A::f(); |
| 746 |
// expected-error@-1 {{friend function 'f' is a private member of 'cwg445::A'}} |
| 747 |
// expected-note@#cwg445-f {{implicitly declared private here}} |
| 748 |
}; |
| 749 |
} // namespace cwg445 |
| 750 |
|
| 751 |
namespace cwg446 { // cwg446: 2.8 |
| 752 |
struct C; |
| 753 |
struct A { |
| 754 |
A(); |
| 755 |
A(const A&) = delete; // #cwg446-deleted |
| 756 |
// cxx98-error@-1 {{deleted function definitions are a C++11 extension}} |
| 757 |
A(const C&); |
| 758 |
}; |
| 759 |
struct C : A {}; |
| 760 |
void f(A a, bool b, C c) { |
| 761 |
void(b ? a : a); |
| 762 |
b ? A() : a; |
| 763 |
// expected-error@-1 {{call to deleted constructor of 'A'}} |
| 764 |
// expected-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}} |
| 765 |
b ? a : A(); |
| 766 |
// expected-error@-1 {{call to deleted constructor of 'A'}} |
| 767 |
// expected-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}} |
| 768 |
b ? A() : A(); |
| 769 |
// cxx98-14-error@-1 {{call to deleted constructor of 'A'}} |
| 770 |
// expected-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}} |
| 771 |
|
| 772 |
void(b ? a : c); |
| 773 |
b ? a : C(); |
| 774 |
// expected-error@-1 {{call to deleted constructor of 'A'}} |
| 775 |
// cxx98-14-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}} |
| 776 |
b ? c : A(); |
| 777 |
// cxx98-14-error@-1 {{call to deleted constructor of 'A'}} |
| 778 |
// cxx98-14-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}} |
| 779 |
b ? A() : C(); |
| 780 |
// cxx98-14-error@-1 {{call to deleted constructor of 'A'}} |
| 781 |
// cxx98-14-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}} |
| 782 |
} |
| 783 |
} // namespace cwg446 |
| 784 |
|
| 785 |
namespace cwg447 { // cwg447: 2.8 |
| 786 |
struct A { int n; int a[4]; }; |
| 787 |
template<int> struct U { |
| 788 |
typedef int type; |
| 789 |
template<typename V> static void h(); |
| 790 |
}; |
| 791 |
template<typename T> U<sizeof(T)> g(T); |
| 792 |
template<typename T, int N> void f(int n) { |
| 793 |
// ok, not type dependent |
| 794 |
g(__builtin_offsetof(A, n)).h<int>(); |
| 795 |
g(__builtin_offsetof(T, n)).h<int>(); |
| 796 |
// value dependent if first argument is a dependent type |
| 797 |
U<__builtin_offsetof(A, n)>::type a; |
| 798 |
// FIXME: instead of ";", we should be suggesting "typename" |
| 799 |
U<__builtin_offsetof(T, n)>::type b; |
| 800 |
// expected-error@-1 {{expected ';' after expression}} |
| 801 |
// expected-error@-2 {{use of undeclared identifier 'b'}} |
| 802 |
// as an extension, we allow the member-designator to include array indices |
| 803 |
g(__builtin_offsetof(A, a[0])).h<int>(); |
| 804 |
g(__builtin_offsetof(A, a[N])).h<int>(); |
| 805 |
U<__builtin_offsetof(A, a[0])>::type c; |
| 806 |
// FIXME: instead of ";", we should be suggesting "typename" |
| 807 |
U<__builtin_offsetof(A, a[N])>::type d; |
| 808 |
// expected-error@-1 {{expected ';' after expression}} |
| 809 |
// expected-error@-2 {{use of undeclared identifier 'd'}} |
| 810 |
} |
| 811 |
} // namespace cwg447 |
| 812 |
|
| 813 |
namespace cwg448 { // cwg448: 2.8 |
| 814 |
template<typename T = int> void f(int); // #cwg448-f-int |
| 815 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 816 |
template<typename T> void g(T t) { |
| 817 |
f<T>(t); |
| 818 |
// expected-error@-1 {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}} |
| 819 |
// expected-note@#cwg448-g {{in instantiation of function template specialization 'cwg448::g<cwg448::HideFromADL::X>' requested here}} |
| 820 |
// expected-note@#cwg448-f-T {{'f' should be declared prior to the call site or in namespace 'cwg448::HideFromADL'}} |
| 821 |
cwg448::f(t); |
| 822 |
// expected-error@-1 {{no matching function for call to 'f'}} |
| 823 |
// expected-note@#cwg448-f-int {{candidate function template not viable: no known conversion from 'cwg448::HideFromADL::X' to 'int' for 1st argument}} |
| 824 |
} |
| 825 |
template<typename T> void f(T); // #cwg448-f-T |
| 826 |
namespace HideFromADL { struct X {}; } |
| 827 |
template void g(int); // ok |
| 828 |
template void g(HideFromADL::X); // #cwg448-g |
| 829 |
} // namespace cwg448 |
| 830 |
|
| 831 |
// cwg449: na |
| 832 |
|
| 833 |
namespace cwg450 { // cwg450: 3.2 |
| 834 |
typedef int A[3]; |
| 835 |
void f1(const A &); |
| 836 |
void f2(A &); // #cwg450-f2 |
| 837 |
struct S { A n; }; |
| 838 |
void g() { |
| 839 |
f1(S().n); |
| 840 |
f2(S().n); |
| 841 |
// expected-error@-1 {{no matching function for call to 'f2'}}} |
| 842 |
// expected-note@#cwg450-f2 {{candidate function not viable: expects an lvalue for 1st argument}} |
| 843 |
} |
| 844 |
#if __cplusplus >= 201103L |
| 845 |
void h() { |
| 846 |
f1(A{}); |
| 847 |
f2(A{}); |
| 848 |
// since-cxx11-error@-1 {{no matching function for call to 'f2'}}} |
| 849 |
// since-cxx11-note@#cwg450-f2 {{candidate function not viable: expects an lvalue for 1st argument}} |
| 850 |
} |
| 851 |
#endif |
| 852 |
} // namespace cwg450 |
| 853 |
|
| 854 |
namespace cwg451 { // cwg451: 2.7 |
| 855 |
const int a = 1 / 0; |
| 856 |
// expected-warning@-1 {{division by zero is undefined}} |
| 857 |
const int b = 1 / 0; // #cwg451-b |
| 858 |
// expected-warning@-1 {{division by zero is undefined}} |
| 859 |
static_assert(b, ""); |
| 860 |
// expected-error@-1 {{expression is not an integral constant expression}} |
| 861 |
// expected-note@-2 {{initializer of 'b' is not a constant expression}} |
| 862 |
// expected-note@#cwg451-b {{declared here}} |
| 863 |
} // namespace cwg451 |
| 864 |
|
| 865 |
namespace cwg452 { // cwg452: 2.7 |
| 866 |
struct A { |
| 867 |
int a, b, c; |
| 868 |
A *p; |
| 869 |
int f(); |
| 870 |
A() : a(f()), b(this->f() + a), c(this->a), p(this) {} |
| 871 |
}; |
| 872 |
} // namespace cwg452 |
| 873 |
|
| 874 |
// cwg454 FIXME write a codegen test |
| 875 |
|
| 876 |
namespace cwg456 { // cwg456: 3.4 |
| 877 |
// sup 903 c++11 |
| 878 |
const int null = 0; |
| 879 |
void *p = null; |
| 880 |
// cxx98-warning@-1 {{expression which evaluates to zero treated as a null pointer constant of type 'void *'}} |
| 881 |
// since-cxx11-error@-2 {{cannot initialize a variable of type 'void *' with an lvalue of type 'const int'}} |
| 882 |
|
| 883 |
const bool f = false; |
| 884 |
void *q = f; |
| 885 |
// cxx98-warning@-1 {{initialization of pointer of type 'void *' to null from a constant boolean}} |
| 886 |
// since-cxx11-error@-2 {{cannot initialize a variable of type 'void *' with an lvalue of type 'const bool'}} |
| 887 |
} // namespace cwg456 |
| 888 |
|
| 889 |
namespace cwg457 { // cwg457: 2.7 |
| 890 |
const int a = 1; |
| 891 |
const volatile int b = 1; |
| 892 |
static_assert(a, ""); |
| 893 |
static_assert(b, ""); |
| 894 |
// expected-error@-1 {{expression is not an integral constant expression}} |
| 895 |
// expected-note@-2 {{read of volatile-qualified type 'const volatile int' is not allowed in a constant expression}} |
| 896 |
|
| 897 |
enum E { |
| 898 |
ea = a, |
| 899 |
eb = b |
| 900 |
// expected-error@-1 {{expression is not an integral constant expression}} |
| 901 |
// expected-note@-2 {{read of volatile-qualified type 'const volatile int' is not allowed in a constant expression}} |
| 902 |
}; |
| 903 |
} // namespace cwg457 |
| 904 |
|
| 905 |
namespace cwg458 { // cwg458: 11 |
| 906 |
struct A { |
| 907 |
int T; |
| 908 |
int f(); |
| 909 |
template<typename> int g(); |
| 910 |
}; |
| 911 |
|
| 912 |
template<typename> struct B : A { |
| 913 |
int f(); |
| 914 |
template<typename> int g(); |
| 915 |
template<typename> int h(); |
| 916 |
}; |
| 917 |
|
| 918 |
int A::f() { |
| 919 |
return T; |
| 920 |
} |
| 921 |
template<typename T> // #cwg458-g-T |
| 922 |
int A::g() { |
| 923 |
return T; |
| 924 |
// expected-error@-1 {{'T' does not refer to a value}} |
| 925 |
// expected-note@#cwg458-g-T {{declared here}} |
| 926 |
} |
| 927 |
|
| 928 |
template<typename T> |
| 929 |
int B<T>::f() { |
| 930 |
return T; |
| 931 |
} |
| 932 |
template<typename T> |
| 933 |
template<typename U> |
| 934 |
int B<T>::g() { |
| 935 |
return T; |
| 936 |
} |
| 937 |
template<typename U> |
| 938 |
template<typename T> // #cwg458-h-T |
| 939 |
int B<U>::h() { |
| 940 |
return T; |
| 941 |
// expected-error@-1 {{'T' does not refer to a value}} |
| 942 |
// expected-note@#cwg458-h-T {{declared here}} |
| 943 |
} |
| 944 |
} // namespace cwg458 |
| 945 |
|
| 946 |
namespace cwg460 { // cwg460: 2.7 |
| 947 |
namespace X { namespace Q { int n; } } |
| 948 |
namespace Y { |
| 949 |
using X; |
| 950 |
// expected-error@-1 {{using declaration requires a qualified name}} |
| 951 |
using cwg460::X; |
| 952 |
// expected-error@-1 {{using declaration cannot refer to a namespace}} |
| 953 |
// expected-note@-2 {{did you mean 'using namespace'?}} |
| 954 |
using X::Q; |
| 955 |
// expected-error@-1 {{using declaration cannot refer to a namespace}} |
| 956 |
// expected-note@-2 {{did you mean 'using namespace'?}} |
| 957 |
} |
| 958 |
} // namespace cwg460 |
| 959 |
|
| 960 |
// cwg461: na |
| 961 |
// cwg462 is in cwg462.cpp |
| 962 |
// cwg463: na |
| 963 |
// cwg464: na |
| 964 |
// cwg465: na |
| 965 |
|
| 966 |
namespace cwg466 { // cwg466: 2.8 |
| 967 |
typedef int I; |
| 968 |
typedef const int CI; |
| 969 |
typedef volatile int VI; |
| 970 |
void g(int a, CI b, VI c) { |
| 971 |
// since-cxx20-warning@-1 {{volatile-qualified parameter type 'VI' (aka 'volatile int') is deprecated}} |
| 972 |
a.~I(); |
| 973 |
a.~CI(); |
| 974 |
a.~VI(); |
| 975 |
a.I::~I(); |
| 976 |
a.CI::~CI(); |
| 977 |
a.VI::~VI(); |
| 978 |
|
| 979 |
a.CI::~VI(); // allowed by changes to [expr.id.prim.qual]/2 introduced in P1131R2 |
| 980 |
|
| 981 |
b.~I(); |
| 982 |
b.~CI(); |
| 983 |
b.~VI(); |
| 984 |
b.I::~I(); |
| 985 |
b.CI::~CI(); |
| 986 |
b.VI::~VI(); |
| 987 |
|
| 988 |
c.~I(); |
| 989 |
c.~CI(); |
| 990 |
c.~VI(); |
| 991 |
c.I::~I(); |
| 992 |
c.CI::~CI(); |
| 993 |
c.VI::~VI(); |
| 994 |
} |
| 995 |
} // namespace cwg466 |
| 996 |
|
| 997 |
namespace cwg467 { // cwg467: 2.7 |
| 998 |
int stuff(); |
| 999 |
|
| 1000 |
int f() { |
| 1001 |
static bool done; |
| 1002 |
if (done) |
| 1003 |
goto later; |
| 1004 |
static int k = stuff(); |
| 1005 |
done = true; |
| 1006 |
later: |
| 1007 |
return k; |
| 1008 |
} |
| 1009 |
int g() { |
| 1010 |
goto later; |
| 1011 |
// expected-error@-1 {{cannot jump from this goto statement to its label}} |
| 1012 |
// expected-note@#cwg467-k {{jump bypasses variable initialization}} |
| 1013 |
int k = stuff(); // #cwg467-k |
| 1014 |
later: |
| 1015 |
return k; |
| 1016 |
} |
| 1017 |
} // namespace cwg467 |
| 1018 |
|
| 1019 |
namespace cwg468 { // cwg468: 2.7 c++11 |
| 1020 |
// FIXME: Should we allow this in C++98 too? |
| 1021 |
template<typename> struct A { |
| 1022 |
template<typename> struct B { |
| 1023 |
static int C; |
| 1024 |
}; |
| 1025 |
}; |
| 1026 |
int k = cwg468::template A<int>::template B<char>::C; |
| 1027 |
// cxx98-error@-1 {{'template' keyword outside of a template}} |
| 1028 |
// cxx98-error@-2 {{'template' keyword outside of a template}} |
| 1029 |
} // namespace cwg468 |
| 1030 |
|
| 1031 |
namespace cwg469 { // cwg469: no |
| 1032 |
template<typename T> struct X; // #cwg469-X |
| 1033 |
template<typename T> struct X<const T> {}; |
| 1034 |
X<int&> x; |
| 1035 |
// expected-error@-1 {{implicit instantiation of undefined template 'cwg469::X<int &>'}} |
| 1036 |
// expected-note@#cwg469-X {{template is declared here}} |
| 1037 |
} // namespace cwg469 |
| 1038 |
|
| 1039 |
namespace cwg470 { // cwg470: 2.7 |
| 1040 |
template<typename T> struct A { |
| 1041 |
struct B {}; |
| 1042 |
}; |
| 1043 |
template<typename T> struct C { |
| 1044 |
}; |
| 1045 |
|
| 1046 |
template struct A<int>; // #cwg470-A-int |
| 1047 |
template struct A<int>::B; |
| 1048 |
// expected-error@-1 {{duplicate explicit instantiation of 'B'}} |
| 1049 |
// expected-note@#cwg470-A-int {{previous explicit instantiation is here}} |
| 1050 |
|
| 1051 |
// ok, instantiating C<char> doesn't instantiate base class members. |
| 1052 |
template struct A<char>; |
| 1053 |
template struct C<char>; |
| 1054 |
} // namespace cwg470 |
| 1055 |
|
| 1056 |
namespace cwg471 { // cwg471: 2.8 |
| 1057 |
struct A { int n; }; |
| 1058 |
struct B : private virtual A {}; |
| 1059 |
struct C : protected virtual A {}; |
| 1060 |
struct D : B, C { int f() { return n; } }; |
| 1061 |
struct E : private virtual A { |
| 1062 |
using A::n; |
| 1063 |
}; |
| 1064 |
struct F : E, B { int f() { return n; } }; |
| 1065 |
struct G : virtual A { |
| 1066 |
private: |
| 1067 |
using A::n; // #cwg471-G-using |
| 1068 |
}; |
| 1069 |
struct H : B, G { int f() { return n; } }; |
| 1070 |
// expected-error@-1 {{'n' is a private member of 'cwg471::G'}} |
| 1071 |
// expected-note@#cwg471-G-using {{declared private here}} |
| 1072 |
} // namespace cwg471 |
| 1073 |
|
| 1074 |
namespace cwg472 { // cwg472: no open 2011-04 |
| 1075 |
struct B { |
| 1076 |
int i; // #cwg472-i |
| 1077 |
}; |
| 1078 |
struct I : protected B {}; // #cwg472-struct-I |
| 1079 |
struct D : public I { |
| 1080 |
void f(I *ip) { |
| 1081 |
ip->i = 0; |
| 1082 |
// expected-error@-1 {{'i' is a protected member of 'cwg472::B'}} |
| 1083 |
// expected-note@#cwg472-struct-I {{constrained by protected inheritance here}} |
| 1084 |
// expected-note@#cwg472-i {{member is declared here}} |
| 1085 |
B *bp = ip; |
| 1086 |
bp->i = 5; |
| 1087 |
} |
| 1088 |
}; |
| 1089 |
} // namespace cwg472 |
| 1090 |
|
| 1091 |
namespace cwg474 { // cwg474: 3.4 |
| 1092 |
namespace N { |
| 1093 |
struct S { |
| 1094 |
void f(); |
| 1095 |
}; |
| 1096 |
} |
| 1097 |
void N::S::f() { |
| 1098 |
void g(); // #cwg474-g |
| 1099 |
} |
| 1100 |
int g(); |
| 1101 |
namespace N { |
| 1102 |
int g(); |
| 1103 |
// expected-error@-1 {{functions that differ only in their return type cannot be overloaded}} |
| 1104 |
// expected-note@#cwg474-g {{previous declaration is here}} |
| 1105 |
} |
| 1106 |
} // namespace cwg474 |
| 1107 |
|
| 1108 |
// cwg475 FIXME write a libc++abi test |
| 1109 |
|
| 1110 |
namespace cwg477 { // cwg477: 3.5 |
| 1111 |
struct A { |
| 1112 |
explicit A(); |
| 1113 |
virtual void f(); |
| 1114 |
}; |
| 1115 |
struct B { |
| 1116 |
friend explicit A::A(); |
| 1117 |
// expected-error@-1 {{'explicit' is invalid in friend declarations}} |
| 1118 |
friend virtual void A::f(); |
| 1119 |
// expected-error@-1 {{'virtual' is invalid in friend declarations}} |
| 1120 |
}; |
| 1121 |
explicit A::A() {} |
| 1122 |
// expected-error@-1 {{can only be specified inside the class definition}} |
| 1123 |
virtual void A::f() {} |
| 1124 |
// expected-error@-1 {{can only be specified inside the class definition}} |
| 1125 |
} // namespace cwg477 |
| 1126 |
|
| 1127 |
namespace cwg478 { // cwg478: 2.7 |
| 1128 |
struct A { virtual void f() = 0; }; // #cwg478-f |
| 1129 |
void f(A *a); |
| 1130 |
void f(A a[10]); |
| 1131 |
// expected-error@-1 {{array of abstract class type 'A'}} |
| 1132 |
// expected-note@#cwg478-f {{unimplemented pure virtual method 'f' in 'A'}} |
| 1133 |
} // namespace cwg478 |
| 1134 |
|
| 1135 |
namespace cwg479 { // cwg479: 2.8 |
| 1136 |
struct S { |
| 1137 |
S(); |
| 1138 |
private: |
| 1139 |
S(const S&); // #cwg479-S-copy-ctor |
| 1140 |
~S(); // #cwg479-S-dtor |
| 1141 |
}; |
| 1142 |
void f() { |
| 1143 |
throw S(); |
| 1144 |
// expected-error@-1 {{temporary of type 'S' has private destructor}} |
| 1145 |
// expected-note@#cwg479-S-dtor {{declared private here}} |
| 1146 |
// expected-error@-3 {{exception object of type 'S' has private destructor}} |
| 1147 |
// expected-note@#cwg479-S-dtor {{declared private here}} |
| 1148 |
// cxx98-error@-5 {{C++98 requires an accessible copy constructor for class 'cwg479::S' when binding a reference to a temporary; was private}} |
| 1149 |
// cxx98-note@#cwg479-S-copy-ctor {{declared private here}} |
| 1150 |
// cxx98-14-error@-7 {{calling a private constructor of class 'cwg479::S'}} |
| 1151 |
// cxx98-14-note@#cwg479-S-copy-ctor {{declared private here}} |
| 1152 |
} |
| 1153 |
void g() { |
| 1154 |
S s; |
| 1155 |
// expected-error@-1 {{variable of type 'S' has private destructor}} |
| 1156 |
// expected-note@#cwg479-S-dtor {{declared private here}} |
| 1157 |
throw s; |
| 1158 |
// expected-error@-1 {{exception object of type 'S' has private destructor}} |
| 1159 |
// expected-note@#cwg479-S-dtor {{declared private here}} |
| 1160 |
// expected-error@-3 {{calling a private constructor of class 'cwg479::S'}} |
| 1161 |
// expected-note@#cwg479-S-copy-ctor {{declared private here}} |
| 1162 |
} |
| 1163 |
void h() { |
| 1164 |
try { |
| 1165 |
f(); |
| 1166 |
g(); |
| 1167 |
} catch (S s) { |
| 1168 |
// expected-error@-1 {{calling a private constructor of class 'cwg479::S'}} |
| 1169 |
// expected-note@#cwg479-S-copy-ctor {{declared private here}} |
| 1170 |
// expected-error@-3 {{variable of type 'S' has private destructor}} |
| 1171 |
// expected-note@#cwg479-S-dtor {{declared private here}} |
| 1172 |
} |
| 1173 |
} |
| 1174 |
} // namespace cwg479 |
| 1175 |
|
| 1176 |
namespace cwg480 { // cwg480: 2.7 |
| 1177 |
struct A { int n; }; |
| 1178 |
struct B : A {}; |
| 1179 |
struct C : virtual B {}; |
| 1180 |
struct D : C {}; |
| 1181 |
|
| 1182 |
int A::*a = &A::n; |
| 1183 |
int D::*b = a; |
| 1184 |
// expected-error@-1 {{conversion from pointer to member of class 'A' to pointer to member of class 'D' via virtual base 'cwg480::B' is not allowed}} |
| 1185 |
|
| 1186 |
extern int D::*c; |
| 1187 |
int A::*d = static_cast<int A::*>(c); |
| 1188 |
// expected-error@-1 {{conversion from pointer to member of class 'cwg480::D' to pointer to member of class 'A' via virtual base 'cwg480::B' is not allowed}} |
| 1189 |
|
| 1190 |
D *e; |
| 1191 |
A *f = e; |
| 1192 |
D *g = static_cast<D*>(f); |
| 1193 |
// expected-error@-1 {{cannot cast 'cwg480::A *' to 'D *' via virtual base 'cwg480::B'}} |
| 1194 |
|
| 1195 |
extern D &i; |
| 1196 |
A &j = i; |
| 1197 |
D &k = static_cast<D&>(j); |
| 1198 |
// expected-error@-1 {{cannot cast 'A' to 'D &' via virtual base 'cwg480::B'}} |
| 1199 |
} // namespace cwg480 |
| 1200 |
|
| 1201 |
namespace cwg481 { // cwg481: 2.8 |
| 1202 |
template<class T, T U> class A { T *x; }; |
| 1203 |
T *x; |
| 1204 |
// expected-error@-1 {{unknown type name 'T'}} |
| 1205 |
|
| 1206 |
template<class T *U> class B { T *x; }; |
| 1207 |
T *y; // ok |
| 1208 |
|
| 1209 |
struct C { |
| 1210 |
template<class T> void f(class D *p); |
| 1211 |
}; |
| 1212 |
D *z; // ok |
| 1213 |
|
| 1214 |
template<typename A = C, typename C = A> struct E { |
| 1215 |
void f() { |
| 1216 |
typedef ::cwg481::C c; // #cwg481-c |
| 1217 |
typedef C c; |
| 1218 |
// expected-error@-1 {{typedef redefinition with different types ('int' vs '::cwg481::C')}} |
| 1219 |
// expected-note@#cwg481-E-int {{in instantiation of member function 'cwg481::E<int>::f' requested here}} |
| 1220 |
// expected-note@#cwg481-c {{previous definition is here}} |
| 1221 |
} |
| 1222 |
}; |
| 1223 |
template struct E<>; // ok |
| 1224 |
template struct E<int>; // #cwg481-E-int |
| 1225 |
|
| 1226 |
template<template<typename U_no_typo_correction> class A, |
| 1227 |
A<int> *B, |
| 1228 |
U_no_typo_correction *C> |
| 1229 |
// expected-error@-1 {{unknown type name 'U_no_typo_correction'}} |
| 1230 |
struct F { |
| 1231 |
U_no_typo_correction *x; |
| 1232 |
// expected-error@-1 {{unknown type name 'U_no_typo_correction'}} |
| 1233 |
}; |
| 1234 |
|
| 1235 |
template<template<class H *> class> struct G { |
| 1236 |
H *x; |
| 1237 |
}; |
| 1238 |
H *q; |
| 1239 |
|
| 1240 |
typedef int N; |
| 1241 |
template<N X, typename N, template<N Y> class T> struct I; |
| 1242 |
template<char*> struct J; |
| 1243 |
I<123, char*, J> *j; |
| 1244 |
} // namespace cwg481 |
| 1245 |
|
| 1246 |
namespace cwg482 { // cwg482: 3.5 |
| 1247 |
extern int a; |
| 1248 |
void f(); |
| 1249 |
|
| 1250 |
int cwg482::a = 0; |
| 1251 |
// expected-warning@-1 {{extra qualification on member 'a'}} |
| 1252 |
void cwg482::f() {} |
| 1253 |
// expected-warning@-1 {{extra qualification on member 'f'}} |
| 1254 |
|
| 1255 |
inline namespace X { |
| 1256 |
// cxx98-error@-1 {{inline namespaces are a C++11 feature}} |
| 1257 |
extern int b; |
| 1258 |
void g(); |
| 1259 |
struct S; |
| 1260 |
} |
| 1261 |
int cwg482::b = 0; |
| 1262 |
// expected-warning@-1 {{extra qualification on member 'b'}} |
| 1263 |
void cwg482::g() {} |
| 1264 |
// expected-warning@-1 {{extra qualification on member 'g'}} |
| 1265 |
struct cwg482::S {}; |
| 1266 |
// expected-warning@-1 {{extra qualification on member 'S'}} |
| 1267 |
|
| 1268 |
void cwg482::f(); |
| 1269 |
// expected-warning@-1 {{extra qualification on member 'f'}} |
| 1270 |
void cwg482::g(); |
| 1271 |
// expected-warning@-1 {{extra qualification on member 'g'}} |
| 1272 |
|
| 1273 |
// FIXME: The following are valid in CWG482's wording, but these are bugs in |
| 1274 |
// the wording which we deliberately don't implement. |
| 1275 |
namespace N { typedef int type; } |
| 1276 |
typedef int N::type; |
| 1277 |
// expected-error@-1 {{typedef declarator cannot be qualified}} |
| 1278 |
struct A { |
| 1279 |
struct B; |
| 1280 |
struct A::B {}; |
| 1281 |
// expected-error@-1 {{extra qualification on member 'B'}} |
| 1282 |
|
| 1283 |
#if __cplusplus >= 201103L |
| 1284 |
enum class C; |
| 1285 |
enum class A::C {}; |
| 1286 |
// since-cxx11-error@-1 {{extra qualification on member 'C'}} |
| 1287 |
#endif |
| 1288 |
}; |
| 1289 |
} // namespace cwg482 |
| 1290 |
|
| 1291 |
namespace cwg483 { // cwg483: 2.7 |
| 1292 |
namespace climits { |
| 1293 |
static_assert(__SCHAR_MAX__ >= 127, ""); |
| 1294 |
static_assert(__SHRT_MAX__ >= 32767, ""); |
| 1295 |
static_assert(__INT_MAX__ >= 32767, ""); |
| 1296 |
static_assert(__LONG_MAX__ >= 2147483647, ""); |
| 1297 |
static_assert(__LONG_LONG_MAX__ >= 9223372036854775807, ""); |
| 1298 |
} |
| 1299 |
namespace cstdint { |
| 1300 |
static_assert(__PTRDIFF_WIDTH__ >= 16, ""); |
| 1301 |
static_assert(__SIG_ATOMIC_WIDTH__ >= 8, ""); |
| 1302 |
static_assert(__SIZE_WIDTH__ >= 16, ""); |
| 1303 |
static_assert(__WCHAR_WIDTH__ >= 8, ""); |
| 1304 |
static_assert(__WINT_WIDTH__ >= 16, ""); |
| 1305 |
} |
| 1306 |
} // namespace cwg483 |
| 1307 |
|
| 1308 |
namespace cwg484 { // cwg484: 2.8 |
| 1309 |
struct A { |
| 1310 |
A(); |
| 1311 |
void f(); |
| 1312 |
}; |
| 1313 |
typedef const A CA; |
| 1314 |
void CA::f() { |
| 1315 |
this->~CA(); |
| 1316 |
this->CA::~A(); |
| 1317 |
this->CA::A::~A(); |
| 1318 |
} |
| 1319 |
CA::A() {} |
| 1320 |
|
| 1321 |
struct B : CA { |
| 1322 |
B() : CA() {} |
| 1323 |
void f() { return CA::f(); } |
| 1324 |
}; |
| 1325 |
|
| 1326 |
struct C; |
| 1327 |
typedef C CT; // #cwg484-typedef-CT |
| 1328 |
struct CT {}; |
| 1329 |
// expected-error@-1 {{definition of type 'CT' conflicts with typedef of the same name}} |
| 1330 |
// expected-note@#cwg484-typedef-CT {{'CT' declared here}} |
| 1331 |
|
| 1332 |
namespace N { |
| 1333 |
struct D; |
| 1334 |
typedef D DT; // #cwg484-typedef-DT |
| 1335 |
} |
| 1336 |
struct N::DT {}; |
| 1337 |
// expected-error@-1 {{definition of type 'DT' conflicts with typedef of the same name}} |
| 1338 |
// expected-note@#cwg484-typedef-DT {{'DT' declared here}} |
| 1339 |
|
| 1340 |
typedef struct { |
| 1341 |
S(); |
| 1342 |
// expected-error@-1 {{a type specifier is required for all declarations}} |
| 1343 |
} S; |
| 1344 |
} // namespace cwg484 |
| 1345 |
|
| 1346 |
namespace cwg485 { // cwg485: 2.7 |
| 1347 |
namespace N { |
| 1348 |
struct S {}; |
| 1349 |
int operator+(S, S); |
| 1350 |
template<typename T> int f(S); |
| 1351 |
} |
| 1352 |
template<typename T> int f(); |
| 1353 |
|
| 1354 |
N::S s; |
| 1355 |
int a = operator+(s, s); |
| 1356 |
int b = f<int>(s); |
| 1357 |
} // namespace cwg485 |
| 1358 |
|
| 1359 |
namespace cwg486 { // cwg486: 2.7 |
| 1360 |
template<typename T> T f(T *); // #cwg486-f |
| 1361 |
int &f(...); |
| 1362 |
|
| 1363 |
void g(); |
| 1364 |
int n[10]; |
| 1365 |
|
| 1366 |
void h() { |
| 1367 |
int &a = f(&g); |
| 1368 |
int &b = f(&n); |
| 1369 |
f<void()>(&g); |
| 1370 |
// expected-error@-1 {{no matching function for call to 'f'}} |
| 1371 |
// expected-note@#cwg486-f {{candidate template ignored: substitution failure [with T = void ()]: function cannot return function type 'void ()'}} |
| 1372 |
f<int[10]>(&n); |
| 1373 |
// expected-error@-1 {{no matching function for call to 'f'}} |
| 1374 |
// expected-note@#cwg486-f {{candidate template ignored: substitution failure [with T = int[10]]: function cannot return array type 'int[10]'}} |
| 1375 |
} |
| 1376 |
} // namespace cwg486 |
| 1377 |
|
| 1378 |
namespace cwg487 { // cwg487: 2.7 |
| 1379 |
enum E { e }; |
| 1380 |
int operator+(int, E); // #cwg487-operator-plus |
| 1381 |
static_assert(4 + e, ""); |
| 1382 |
// expected-error@-1 {{expression is not an integral constant expression}} |
| 1383 |
// since-cxx11-note@-2 {{non-constexpr function 'operator+' cannot be used in a constant expression}} |
| 1384 |
// since-cxx11-note@#cwg487-operator-plus {{declared here}} |
| 1385 |
} // namespace cwg487 |
| 1386 |
|
| 1387 |
namespace cwg488 { // cwg488: 2.9 c++11 |
| 1388 |
template <typename T> void f(T); |
| 1389 |
void f(int); |
| 1390 |
void g() { |
| 1391 |
// FIXME: It seems CWG thought this should be a SFINAE failure prior to |
| 1392 |
// allowing local types as template arguments. In C++98, we should either |
| 1393 |
// allow local types as template arguments or treat this as a SFINAE |
| 1394 |
// failure. |
| 1395 |
enum E { e }; |
| 1396 |
f(e); |
| 1397 |
// cxx98-error@-1 {{template argument uses local type 'E'}} |
| 1398 |
// cxx98-note@-2 {{while substituting deduced template arguments}} |
| 1399 |
} |
| 1400 |
} // namespace cwg488 |
| 1401 |
|
| 1402 |
// cwg489: na |
| 1403 |
|
| 1404 |
namespace cwg490 { // cwg490: 2.8 |
| 1405 |
template<typename T> struct X {}; |
| 1406 |
|
| 1407 |
struct A { |
| 1408 |
typedef int T; |
| 1409 |
struct K {}; // #cwg490-k |
| 1410 |
|
| 1411 |
int f(T); |
| 1412 |
int g(T); |
| 1413 |
int h(X<T>); |
| 1414 |
int X<T>::*i(); // #cwg490-i |
| 1415 |
int K::*j(); |
| 1416 |
|
| 1417 |
template<typename T> T k(); |
| 1418 |
|
| 1419 |
operator X<T>(); |
| 1420 |
}; |
| 1421 |
|
| 1422 |
struct B { |
| 1423 |
typedef char T; |
| 1424 |
typedef int U; |
| 1425 |
friend int A::f(T); |
| 1426 |
friend int A::g(U); |
| 1427 |
friend int A::h(X<T>); |
| 1428 |
|
| 1429 |
// FIXME: Per this DR, these two are valid! That is another defect |
| 1430 |
// (no number yet...) which will eventually supersede this one. |
| 1431 |
friend int X<T>::*A::i(); |
| 1432 |
// expected-error@-1 {{return type of out-of-line definition of 'cwg490::A::i' differs from that in the declaration}} |
| 1433 |
// expected-note@#cwg490-i {{previous declaration is here}} |
| 1434 |
friend int K::*A::j(); |
| 1435 |
// expected-error@-1 {{use of undeclared identifier 'K'; did you mean 'A::K'?}} |
| 1436 |
// expected-note@#cwg490-k {{'A::K' declared here}} |
| 1437 |
|
| 1438 |
// ok, lookup finds B::T, not A::T, so return type matches |
| 1439 |
friend char A::k<T>(); |
| 1440 |
friend int A::k<U>(); |
| 1441 |
|
| 1442 |
// A conversion-type-id in a conversion-function-id is always looked up in |
| 1443 |
// the class of the conversion function first. |
| 1444 |
friend A::operator X<T>(); |
| 1445 |
}; |
| 1446 |
} // namespace cwg490 |
| 1447 |
|
| 1448 |
namespace cwg491 { // cwg491: dup 413 |
| 1449 |
struct A {} a, b[3] = { a, {} }; |
| 1450 |
A c[2] = { a, {}, b[1] }; |
| 1451 |
// expected-error@-1 {{excess elements in array initializer}} |
| 1452 |
} // namespace cwg491 |
| 1453 |
|
| 1454 |
// cwg492 is in cwg492.cpp |
| 1455 |
|
| 1456 |
namespace cwg493 { // cwg493: dup 976 |
| 1457 |
struct X { |
| 1458 |
template <class T> operator const T &() const; |
| 1459 |
}; |
| 1460 |
void f() { |
| 1461 |
if (X()) { |
| 1462 |
} |
| 1463 |
} |
| 1464 |
} // namespace cwg493 |
| 1465 |
|
| 1466 |
namespace cwg494 { // cwg494: dup 372 |
| 1467 |
class A { |
| 1468 |
class B {}; |
| 1469 |
friend class C; |
| 1470 |
}; |
| 1471 |
class C : A::B { |
| 1472 |
A::B x; |
| 1473 |
class D : A::B { |
| 1474 |
A::B y; |
| 1475 |
}; |
| 1476 |
}; |
| 1477 |
} // namespace cwg494 |
| 1478 |
|
| 1479 |
namespace cwg495 { // cwg495: 3.5 |
| 1480 |
template<typename T> |
| 1481 |
struct S { |
| 1482 |
operator int() { return T::error; } |
| 1483 |
template<typename U> operator U(); |
| 1484 |
}; |
| 1485 |
S<int> s; |
| 1486 |
long n = s; |
| 1487 |
|
| 1488 |
template<typename T> |
| 1489 |
struct S2 { |
| 1490 |
template<typename U> operator U(); |
| 1491 |
operator int() { return T::error; } |
| 1492 |
}; |
| 1493 |
S2<int> s2; |
| 1494 |
long n2 = s2; |
| 1495 |
} // namespace cwg495 |
| 1496 |
|
| 1497 |
namespace cwg496 { // cwg496: sup 2094 |
| 1498 |
struct A { int n; }; |
| 1499 |
struct B { volatile int n; }; |
| 1500 |
static_assert(__is_trivially_copyable(const int), ""); |
| 1501 |
// This checks the cwg2094 behavior, not cwg496 |
| 1502 |
static_assert(__is_trivially_copyable(volatile int), ""); |
| 1503 |
static_assert(__is_trivially_constructible(A, const A&), ""); |
| 1504 |
static_assert(__is_trivially_constructible(B, const B&), ""); |
| 1505 |
static_assert(__is_trivially_assignable(A, const A&), ""); |
| 1506 |
static_assert(__is_trivially_assignable(B, const B&), ""); |
| 1507 |
} // namespace cwg496 |
| 1508 |
|
| 1509 |
namespace cwg497 { // cwg497: sup 253 |
| 1510 |
void before() { |
| 1511 |
struct S { |
| 1512 |
mutable int i; |
| 1513 |
}; |
| 1514 |
const S cs; |
| 1515 |
int S::*pm = &S::i; |
| 1516 |
cs.*pm = 88; |
| 1517 |
// expected-error@-1 {{read-only variable is not assignable}} |
| 1518 |
} |
| 1519 |
|
| 1520 |
void after() { |
| 1521 |
struct S { |
| 1522 |
S() : i(0) {} |
| 1523 |
mutable int i; |
| 1524 |
}; |
| 1525 |
const S cs; |
| 1526 |
int S::*pm = &S::i; |
| 1527 |
cs.*pm = 88; |
| 1528 |
// expected-error@-1 {{read-only variable is not assignable}} |
| 1529 |
} |
| 1530 |
} // namespace cwg497 |
| 1531 |
|
| 1532 |
namespace cwg499 { // cwg499: 2.7 |
| 1533 |
extern char str[]; |
| 1534 |
void f() { throw str; } |
| 1535 |
} // namespace cwg499 |