| 1 |
// RUN: %clang_cc1 -std=c++98 -verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx98 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors |
| 2 |
// RUN: %clang_cc1 -std=c++11 -verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx11-14,since-cxx11 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors |
| 3 |
// RUN: %clang_cc1 -std=c++14 -verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx11-14,since-cxx11 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors |
| 4 |
// RUN: %clang_cc1 -std=c++17 -verify=expected,cxx98-17,cxx98-20,since-cxx11,since-cxx17 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors |
| 5 |
// RUN: %clang_cc1 -std=c++20 -verify=expected,cxx98-20,cxx20-23,since-cxx11,since-cxx17 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors |
| 6 |
// RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20-23,cxx23,since-cxx11,since-cxx17,since-cxx23 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors |
| 7 |
// RUN: %clang_cc1 -std=c++2c -verify=expected,cxx20-23,cxx23,since-cxx11,since-cxx17,since-cxx23 -triple %itanium_abi_triple %s -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 |
#if __cplusplus == 199711L |
| 15 |
#define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x)) |
| 16 |
#else |
| 17 |
#define __enable_constant_folding |
| 18 |
#endif |
| 19 |
|
| 20 |
namespace cwg300 { // cwg300: 2.7 |
| 21 |
template<typename R, typename A> void f(R (&)(A)) {} |
| 22 |
int g(int); |
| 23 |
void h() { f(g); } |
| 24 |
} // namespace cwg300 |
| 25 |
|
| 26 |
namespace cwg301 { // cwg301: 3.5 |
| 27 |
// see also cwg38 |
| 28 |
struct S; |
| 29 |
template<typename T> void operator+(T, T); |
| 30 |
void operator-(S, S); |
| 31 |
|
| 32 |
void f() { |
| 33 |
bool a = (void(*)(S, S))operator+<S> < (void(*)(S, S))operator+<S>; |
| 34 |
// expected-warning@-1 {{ordered comparison of function pointers ('void (*)(S, S)' and 'void (*)(S, S)')}} |
| 35 |
bool b = (void(*)(S, S))operator- < (void(*)(S, S))operator-; |
| 36 |
// cxx98-17-warning@-1 {{ordered comparison of function pointers ('void (*)(S, S)' and 'void (*)(S, S)')}} |
| 37 |
// cxx20-23-error@-2 {{expected '>'}} |
| 38 |
// cxx20-23-note@-3 {{to match this '<'}} |
| 39 |
bool c = (void(*)(S, S))operator+ < (void(*)(S, S))operator-; |
| 40 |
// expected-error@-1 {{expected '>'}} |
| 41 |
// expected-note@-2 {{to match this '<'}} |
| 42 |
} |
| 43 |
|
| 44 |
template<typename T> void f() { |
| 45 |
// FIXME: We are emitting a lot of bogus diagnostics here. |
| 46 |
typename T::template operator+<int> a; |
| 47 |
// expected-error@-1 {{typename specifier refers to a non-type template}} |
| 48 |
// expected-error@-2 {{'template' keyword not permitted here}} |
| 49 |
// expected-error@-3 {{a type specifier is required for all declarations}} |
| 50 |
// expected-error@-4 {{'operator+' cannot be the name of a variable or data member}} |
| 51 |
// expected-error@-5 {{expected ';' at end of declaration}} |
| 52 |
// FIXME: This shouldn't say (null). |
| 53 |
class T::template operator+<int> b; |
| 54 |
// expected-error@-1 {{identifier followed by '<' indicates a class template specialization but (null) refers to a function template}} |
| 55 |
enum T::template operator+<int> c; |
| 56 |
// expected-error@-1 {{expected identifier}} |
| 57 |
enum T::template operator+<int>::E d; |
| 58 |
// expected-error@-1 {{qualified name refers into a specialization of function template 'T::template operator +'}} |
| 59 |
// expected-error@-2 {{ISO C++ forbids forward references to 'enum' types}} |
| 60 |
enum T::template X<int>::E e; |
| 61 |
T::template operator+<int>::foobar(); |
| 62 |
// expected-error@-1 {{qualified name refers into a specialization of function template 'T::template operator +'}} |
| 63 |
T::template operator+<int>(0); // ok |
| 64 |
} |
| 65 |
|
| 66 |
// FIXME: We are emitting a bunch of bogus diagnostics for the next 3 lines. |
| 67 |
// All of them do a bad job at explaining that 'class' is not allowed here. |
| 68 |
template<typename T> class operator&<T*> {}; |
| 69 |
// expected-error@-1 {{declaration of anonymous class must be a definition}} |
| 70 |
// expected-error@-2 {{declaration does not declare anything}} |
| 71 |
template<typename T> class T::operator& {}; |
| 72 |
// expected-error@-1 {{expected identifier}} |
| 73 |
// expected-error@-2 {{declaration of anonymous class must be a definition}} |
| 74 |
// expected-error@-3 {{declaration does not declare anything}} |
| 75 |
template<typename T> class S::operator&<T*> {}; |
| 76 |
// expected-error@-1 {{expected identifier}} |
| 77 |
// expected-error@-2 {{declaration of anonymous class must be a definition}} |
| 78 |
// expected-error@-3 {{declaration does not declare anything}} |
| 79 |
} // namespace cwg301 |
| 80 |
|
| 81 |
namespace cwg302 { // cwg302: 3.0 |
| 82 |
struct A { A(); ~A(); }; |
| 83 |
#if __cplusplus < 201103L |
| 84 |
struct B { |
| 85 |
// expected-error@-1 {{implicit default constructor for 'cwg302::B' must explicitly initialize the const member 'n'}} |
| 86 |
// expected-note@#cwg302-b {{in implicit default constructor for 'cwg302::B' first required here}} |
| 87 |
// expected-note@#cwg302-B-n {{declared here}} |
| 88 |
const int n; // #cwg302-B-n |
| 89 |
A a; |
| 90 |
} b = B(); // #cwg302-b |
| 91 |
// Trivial default constructor C::C() is not called here. |
| 92 |
struct C { |
| 93 |
const int n; |
| 94 |
} c = C(); |
| 95 |
#else |
| 96 |
struct B { |
| 97 |
const int n; // #cwg302-B-n |
| 98 |
A a; |
| 99 |
} b = B(); |
| 100 |
// expected-error@-1 {{call to implicitly-deleted default constructor of 'B'}} |
| 101 |
// expected-note@#cwg302-B-n {{default constructor of 'B' is implicitly deleted because field 'n' of const-qualified type 'const int' would not be initialized}} |
| 102 |
// C::C() is called here, because even though it's trivial, it's deleted. |
| 103 |
struct C { |
| 104 |
const int n; // #cwg302-C-n |
| 105 |
} c = C(); |
| 106 |
// expected-error@-1 {{call to implicitly-deleted default constructor of 'C'}} |
| 107 |
// expected-note@#cwg302-C-n {{default constructor of 'C' is implicitly deleted because field 'n' of const-qualified type 'const int' would not be initialized}} |
| 108 |
struct D { |
| 109 |
const int n = 0; |
| 110 |
} d = D(); |
| 111 |
#endif |
| 112 |
} // namespace cwg302 |
| 113 |
|
| 114 |
// cwg303: na |
| 115 |
|
| 116 |
namespace cwg304 { // cwg304: 2.9 |
| 117 |
typedef int &a; |
| 118 |
int n = a(); |
| 119 |
// expected-error@-1 {{reference to type 'int' requires an initializer}} |
| 120 |
|
| 121 |
struct S { int &b; }; // #cwg304-S |
| 122 |
// cxx98-error@-1 {{reference to type 'int' requires an initializer}} |
| 123 |
// cxx98-note@#cwg304-m {{in value-initialization of type 'S' here}} |
| 124 |
int m = S().b; // #cwg304-m |
| 125 |
// since-cxx11-error@-1 {{call to implicitly-deleted default constructor of 'S'}} |
| 126 |
// since-cxx11-note@#cwg304-S {{default constructor of 'S' is implicitly deleted because field 'b' of reference type 'int &' would not be initialized}} |
| 127 |
} // namespace cwg304 |
| 128 |
|
| 129 |
namespace cwg305 { // cwg305: no |
| 130 |
struct A { |
| 131 |
typedef A C; |
| 132 |
}; |
| 133 |
void f(A *a) { |
| 134 |
struct A {}; |
| 135 |
a->~A(); |
| 136 |
a->~C(); |
| 137 |
} |
| 138 |
typedef A B; |
| 139 |
void g(B *b) { |
| 140 |
b->~B(); |
| 141 |
b->~C(); |
| 142 |
} |
| 143 |
void h(B *b) { |
| 144 |
struct B {}; // #cwg305-h-B |
| 145 |
b->~B(); |
| 146 |
// expected-error@-1 {{destructor type 'B' in object destruction expression does not match the type 'B' (aka 'A') of the object being destroyed}} |
| 147 |
// expected-note@#cwg305-h-B {{type 'B' found by destructor name lookup}} |
| 148 |
} |
| 149 |
|
| 150 |
template<typename T> struct X {}; |
| 151 |
void i(X<int>* x) { |
| 152 |
struct X {}; |
| 153 |
x->~X<int>(); |
| 154 |
x->~X(); |
| 155 |
x->~X<char>(); |
| 156 |
// expected-error@-1 {{no member named '~X' in 'cwg305::X<int>'}} |
| 157 |
} |
| 158 |
|
| 159 |
#if __cplusplus >= 201103L |
| 160 |
struct Y { |
| 161 |
template<typename T> using T1 = Y; |
| 162 |
}; |
| 163 |
template<typename T> using T2 = Y; |
| 164 |
void j(Y *y) { |
| 165 |
y->~T1<int>(); |
| 166 |
y->~T2<int>(); |
| 167 |
} |
| 168 |
struct Z { |
| 169 |
template<typename T> using T2 = T; |
| 170 |
}; |
| 171 |
void k(Z *z) { |
| 172 |
z->~T1<int>(); |
| 173 |
// since-cxx11-error@-1 {{no member named 'T1' in 'cwg305::Z'}} |
| 174 |
z->~T2<int>(); |
| 175 |
// since-cxx11-error@-1 {{no member named '~int' in 'cwg305::Z'}} |
| 176 |
z->~T2<Z>(); |
| 177 |
} |
| 178 |
|
| 179 |
// FIXME: This is valid. |
| 180 |
namespace Q { |
| 181 |
template<typename A> struct R {}; |
| 182 |
} |
| 183 |
template<typename A> using R = Q::R<int>; |
| 184 |
void qr(Q::R<int> x) { x.~R<char>(); } |
| 185 |
// since-cxx11-error@-1 {{no member named '~R' in 'cwg305::Q::R<int>'}} |
| 186 |
#endif |
| 187 |
} // namespace cwg305 |
| 188 |
|
| 189 |
namespace cwg306 { // cwg306: dup 39 |
| 190 |
struct A { struct B {}; }; |
| 191 |
struct C { typedef A::B B; }; |
| 192 |
struct D : A, A::B, C {}; |
| 193 |
D::B b; |
| 194 |
|
| 195 |
struct X {}; // #cwg306-X |
| 196 |
template<typename T> struct Y { typedef T X; }; // #cwg306-typedef-X |
| 197 |
template<typename T> struct Z : X, Y<T> {}; |
| 198 |
Z<X>::X zx; |
| 199 |
Z<const X>::X zcx; |
| 200 |
// expected-error@-1 {{member 'X' found in multiple base classes of different types}} |
| 201 |
// expected-note@#cwg306-X {{member type 'cwg306::X' found}} |
| 202 |
// expected-note@#cwg306-typedef-X {{member type 'const cwg306::X' found}} |
| 203 |
} // namespace cwg306 |
| 204 |
|
| 205 |
// cwg307: na |
| 206 |
|
| 207 |
namespace cwg308 { // cwg308: 3.7 |
| 208 |
// This is mostly an ABI library issue. |
| 209 |
struct A {}; |
| 210 |
struct B : A {}; |
| 211 |
struct C : A {}; |
| 212 |
struct D : B, C {}; |
| 213 |
void f() { |
| 214 |
// NB: the warning here is correct despite being the opposite of the |
| 215 |
// comments in the catch handlers. The "unreachable" comment is correct |
| 216 |
// because there is an ambiguous base path to A from the D that is thrown. |
| 217 |
// The warnings generated are also correct because the handlers handle |
| 218 |
// const B& and const A& and we don't check to see if other derived classes |
| 219 |
// exist that would cause an ambiguous base path. We issue the diagnostic |
| 220 |
// despite the potential for a false positive because users are not |
| 221 |
// expected to have ambiguous base paths all that often, so the false |
| 222 |
// positive rate should be acceptably low. |
| 223 |
try { |
| 224 |
throw D(); |
| 225 |
} catch (const A&) { // #cwg308-catch-A |
| 226 |
// unreachable |
| 227 |
} catch (const B&) { |
| 228 |
// expected-warning@-1 {{exception of type 'const B &' will be caught by earlier handler}} |
| 229 |
// expected-note@#cwg308-catch-A {{for type 'const A &'}} |
| 230 |
// get here instead |
| 231 |
} |
| 232 |
} |
| 233 |
} // namespace cwg308 |
| 234 |
|
| 235 |
// cwg309: dup 485 |
| 236 |
|
| 237 |
namespace cwg311 { // cwg311: 3.0 |
| 238 |
namespace X { namespace Y {} } |
| 239 |
namespace X::Y {} |
| 240 |
// cxx98-14-error@-1 {{nested namespace definition is a C++17 extension; define each namespace separately}} |
| 241 |
namespace X { |
| 242 |
namespace X::Y {} |
| 243 |
// cxx98-14-error@-1 {{nested namespace definition is a C++17 extension; define each namespace separately}} |
| 244 |
} |
| 245 |
// FIXME: The diagnostics here are not very good. |
| 246 |
namespace ::cwg311::X {} |
| 247 |
// expected-error@-1 {{expected identifier or '{'}} |
| 248 |
// expected-warning@-2 {{extra qualification on member 'X'}} |
| 249 |
// expected-error@-3 {{a type specifier is required for all declarations}} |
| 250 |
// expected-error@-4 {{expected ';' after top level declarator}} |
| 251 |
} // namespace cwg311 |
| 252 |
|
| 253 |
// cwg312: dup 616 |
| 254 |
|
| 255 |
namespace cwg313 { // cwg313: dup 299 c++11 |
| 256 |
struct A { operator int() const; }; |
| 257 |
// FIXME: should this be available in c++98 mode? |
| 258 |
int *p = new int[A()]; |
| 259 |
// cxx98-error@-1 {{implicit conversion from array size expression of type 'A' to integral type 'int' is a C++11 extension}} |
| 260 |
} // namespace cwg313 |
| 261 |
|
| 262 |
namespace cwg314 { // cwg314: no |
| 263 |
// NB: dup 1710 |
| 264 |
template <typename T> struct A { |
| 265 |
template <typename U> struct B {}; |
| 266 |
}; |
| 267 |
template <typename T> struct C : public A<T>::template B<T> { |
| 268 |
C() : A<T>::template B<T>() {} |
| 269 |
}; |
| 270 |
template <typename T> struct C2 : public A<T>::B<T> { |
| 271 |
// expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}} |
| 272 |
C2() : A<T>::B<T>() {} |
| 273 |
// expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}} |
| 274 |
}; |
| 275 |
} // namespace cwg314 |
| 276 |
|
| 277 |
// cwg315: na |
| 278 |
// cwg316: sup 1004 |
| 279 |
|
| 280 |
namespace cwg317 { // cwg317: 3.5 |
| 281 |
void f() {} // #cwg317-f |
| 282 |
inline void f(); |
| 283 |
// expected-error@-1 {{inline declaration of 'f' follows non-inline definition}} |
| 284 |
// expected-note@#cwg317-f {{previous definition is here}} |
| 285 |
|
| 286 |
int g(); |
| 287 |
int n = g(); |
| 288 |
inline int g() { return 0; } |
| 289 |
|
| 290 |
int h(); |
| 291 |
int m = h(); |
| 292 |
int h() { return 0; } // #cwg317-h |
| 293 |
inline int h(); |
| 294 |
// expected-error@-1 {{inline declaration of 'h' follows non-inline definition}} |
| 295 |
// expected-note@#cwg317-h {{previous definition is here}} |
| 296 |
} // namespace cwg317 |
| 297 |
|
| 298 |
namespace cwg318 { // cwg318: sup 1310 |
| 299 |
struct A {}; |
| 300 |
struct A::A a; |
| 301 |
} // namespace cwg318 |
| 302 |
|
| 303 |
namespace cwg319 { // cwg319: no |
| 304 |
// FIXME: dup cwg389 |
| 305 |
// FIXME: We don't have a diagnostic for a name with linkage |
| 306 |
// having a type without linkage. |
| 307 |
typedef struct { |
| 308 |
int i; |
| 309 |
} *ps; |
| 310 |
extern "C" void f(ps); |
| 311 |
void g(ps); // FIXME: ill-formed, type 'ps' has no linkage |
| 312 |
|
| 313 |
static enum { e } a1; |
| 314 |
enum { e2 } a2; // FIXME: ill-formed, enum type has no linkage |
| 315 |
|
| 316 |
enum { n1 = 1u }; |
| 317 |
typedef int (*pa)[n1]; |
| 318 |
pa parr; // ok, type has linkage despite using 'n1' |
| 319 |
|
| 320 |
template<typename> struct X {}; |
| 321 |
|
| 322 |
void f() { |
| 323 |
struct A { int n; }; |
| 324 |
extern A a; // FIXME: ill-formed |
| 325 |
X<A> xa; |
| 326 |
// cxx98-error@-1 {{template argument uses local type 'A'}} |
| 327 |
|
| 328 |
typedef A B; |
| 329 |
extern B b; // FIXME: ill-formed |
| 330 |
X<B> xb; |
| 331 |
// cxx98-error@-1 {{template argument uses local type 'A'}} |
| 332 |
|
| 333 |
const int n = 1; |
| 334 |
typedef int (*C)[n]; |
| 335 |
extern C c; // ok |
| 336 |
X<C> xc; |
| 337 |
} |
| 338 |
} // namespace cwg319 |
| 339 |
|
| 340 |
namespace cwg320 { // cwg320: 3.1 |
| 341 |
#if __cplusplus >= 201103L |
| 342 |
struct X { |
| 343 |
constexpr X() {} |
| 344 |
constexpr X(const X &x) : copies(x.copies + 1) {} |
| 345 |
unsigned copies = 0; |
| 346 |
}; |
| 347 |
constexpr X f(X x) { return x; } |
| 348 |
constexpr unsigned g(X x) { return x.copies; } |
| 349 |
static_assert(f(X()).copies == g(X()) + 1, "expected one extra copy for return value"); |
| 350 |
#endif |
| 351 |
} // namespace cwg320 |
| 352 |
|
| 353 |
namespace cwg321 { // cwg321: dup 557 |
| 354 |
namespace N { |
| 355 |
template<int> struct A { |
| 356 |
template<int> struct B; |
| 357 |
}; |
| 358 |
template<> template<> struct A<0>::B<0>; |
| 359 |
void f(A<0>::B<0>); |
| 360 |
} |
| 361 |
template<> template<> struct N::A<0>::B<0> {}; |
| 362 |
|
| 363 |
template<typename T> void g(T t) { f(t); } |
| 364 |
template void g(N::A<0>::B<0>); |
| 365 |
|
| 366 |
namespace N { |
| 367 |
template<typename> struct I { friend bool operator==(const I&, const I&); }; |
| 368 |
} |
| 369 |
N::I<int> i, j; |
| 370 |
bool x = i == j; |
| 371 |
} // namespace cwg321 |
| 372 |
|
| 373 |
namespace cwg322 { // cwg322: 2.8 |
| 374 |
struct A { |
| 375 |
template<typename T> operator T&(); |
| 376 |
} a; |
| 377 |
int &r = static_cast<int&>(a); |
| 378 |
int &s = a; |
| 379 |
} // namespace cwg322 |
| 380 |
|
| 381 |
// cwg323: sup 820 |
| 382 |
|
| 383 |
namespace cwg324 { // cwg324: 3.6 |
| 384 |
struct S { int n : 1; } s; // #cwg324-n |
| 385 |
int &a = s.n; |
| 386 |
// expected-error@-1 {{non-const reference cannot bind to bit-field 'n'}} |
| 387 |
// expected-note@#cwg324-n {{bit-field is declared here}} |
| 388 |
int *b = &s.n; |
| 389 |
// expected-error@-1 {{address of bit-field requested}} |
| 390 |
int &c = (s.n = 0); |
| 391 |
// expected-error@-1 {{non-const reference cannot bind to bit-field 'n'}} |
| 392 |
// expected-note@#cwg324-n {{bit-field is declared here}} |
| 393 |
int *d = &(s.n = 0); |
| 394 |
// expected-error@-1 {{address of bit-field requested}} |
| 395 |
// FIXME: why don't we emit a note here, as for the rest of this type of diagnostic in this test? |
| 396 |
int &e = true ? s.n : s.n; |
| 397 |
// expected-error@-1 {{non-const reference cannot bind to bit-field}} |
| 398 |
int *f = &(true ? s.n : s.n); |
| 399 |
// expected-error@-1 {{address of bit-field requested}} |
| 400 |
int &g = (void(), s.n); |
| 401 |
// expected-error@-1 {{non-const reference cannot bind to bit-field 'n'}} |
| 402 |
// expected-note@#cwg324-n {{bit-field is declared here}} |
| 403 |
int *h = &(void(), s.n); |
| 404 |
// expected-error@-1 {{address of bit-field requested}} |
| 405 |
int *i = &++s.n; |
| 406 |
// expected-error@-1 {{address of bit-field requested}} |
| 407 |
} // namespace cwg324 |
| 408 |
|
| 409 |
namespace cwg326 { // cwg326: 3.1 |
| 410 |
struct S {}; |
| 411 |
static_assert(__is_trivially_constructible(S, const S&), ""); |
| 412 |
} // namespace cwg326 |
| 413 |
|
| 414 |
namespace cwg327 { // cwg327: dup 538 |
| 415 |
struct A; |
| 416 |
class A {}; |
| 417 |
|
| 418 |
class B; |
| 419 |
struct B {}; |
| 420 |
} // namespace cwg327 |
| 421 |
|
| 422 |
namespace cwg328 { // cwg328: 2.7 |
| 423 |
struct A; // #cwg328-A |
| 424 |
struct B { A a; }; |
| 425 |
// expected-error@-1 {{field has incomplete type 'A'}} |
| 426 |
// expected-note@#cwg328-A {{forward declaration of 'cwg328::A'}} |
| 427 |
template<typename> struct C { A a; }; |
| 428 |
// expected-error@-1 {{field has incomplete type 'A'}} |
| 429 |
// expected-note@#cwg328-A {{forward declaration of 'cwg328::A'}} |
| 430 |
A *p = new A[0]; |
| 431 |
// expected-error@-1 {{allocation of incomplete type 'A'}} |
| 432 |
// expected-note@#cwg328-A {{forward declaration of 'cwg328::A'}} |
| 433 |
} // namespace cwg328 |
| 434 |
|
| 435 |
namespace cwg329 { // cwg329: 3.5 |
| 436 |
struct B {}; |
| 437 |
template<typename T> struct A : B { |
| 438 |
friend void f(A a) { g(a); } |
| 439 |
friend void h(A a) { g(a); } |
| 440 |
// expected-error@-1 {{use of undeclared identifier 'g'}} |
| 441 |
// expected-note@#cwg329-h-call {{in instantiation of member function 'cwg329::h' requested here}} |
| 442 |
friend void i(B b) {} // #cwg329-i |
| 443 |
// expected-error@-1 {{redefinition of 'i'}} |
| 444 |
// expected-note@#cwg329-b {{in instantiation of template class 'cwg329::A<char>' requested here}} |
| 445 |
// expected-note@#cwg329-i {{previous definition is here}} |
| 446 |
}; |
| 447 |
A<int> a; |
| 448 |
A<char> b; // #cwg329-b |
| 449 |
|
| 450 |
void test() { |
| 451 |
h(a); // #cwg329-h-call |
| 452 |
} |
| 453 |
} // namespace cwg329 |
| 454 |
|
| 455 |
namespace cwg330 { // cwg330: 7 |
| 456 |
// Conversions between P and Q will be allowed by P0388. |
| 457 |
typedef int *(*P)[3]; |
| 458 |
typedef const int *const (*Q)[3]; |
| 459 |
typedef const int *Qinner[3]; |
| 460 |
typedef Qinner const *Q2; // same as Q, but 'const' written outside the array type |
| 461 |
typedef const int *const (*R)[4]; |
| 462 |
typedef const int *const (*S)[]; |
| 463 |
typedef const int *(*T)[]; |
| 464 |
void f(P p, Q q, Q2 q2, R r, S s, T t) { |
| 465 |
q = p; // ok |
| 466 |
q2 = p; // ok |
| 467 |
r = p; |
| 468 |
// expected-error@-1 {{incompatible pointer types assigning to 'R' (aka 'const int *const (*)[4]') from 'P' (aka 'int *(*)[3]')}} |
| 469 |
s = p; |
| 470 |
// cxx98-17-error@-1 {{incompatible pointer types assigning to 'S' (aka 'const int *const (*)[]') from 'P' (aka 'int *(*)[3]')}} (fixed by p0388) |
| 471 |
t = p; |
| 472 |
// expected-error@-1 {{incompatible pointer types assigning to 'T' (aka 'const int *(*)[]') from 'P' (aka 'int *(*)[3]')}} |
| 473 |
s = q; |
| 474 |
// cxx98-17-error@-1 {{incompatible pointer types assigning to 'S' (aka 'const int *const (*)[]') from 'Q' (aka 'const int *const (*)[3]')}} (fixed by p0388) |
| 475 |
s = q2; |
| 476 |
// cxx98-17-error@-1 {{incompatible pointer types assigning to 'S' (aka 'const int *const (*)[]') from 'Q2' (aka 'const int *const (*)[3]')}} (fixed by p0388) |
| 477 |
s = t; // ok, adding const |
| 478 |
t = s; |
| 479 |
// expected-error@-1 {{assigning to 'T' (aka 'const int *(*)[]') from 'S' (aka 'const int *const (*)[]') discards qualifiers}} |
| 480 |
(void) const_cast<P>(q); |
| 481 |
(void) const_cast<P>(q2); |
| 482 |
(void) const_cast<Q>(p); |
| 483 |
(void) const_cast<Q2>(p); |
| 484 |
(void) const_cast<S>(p); |
| 485 |
// expected-error@-1 {{const_cast from 'P' (aka 'int *(*)[3]') to 'S' (aka 'const int *const (*)[]') is not allowed}} (for now) |
| 486 |
(void) const_cast<P>(s); |
| 487 |
// expected-error@-1 {{const_cast from 'S' (aka 'const int *const (*)[]') to 'P' (aka 'int *(*)[3]') is not allowed}} (for now) |
| 488 |
(void) const_cast<S>(q); |
| 489 |
// expected-error@-1 {{const_cast from 'Q' (aka 'const int *const (*)[3]') to 'S' (aka 'const int *const (*)[]') is not allowed}} |
| 490 |
(void) const_cast<S>(q2); |
| 491 |
// expected-error@-1 {{const_cast from 'Q2' (aka 'const int *const (*)[3]') to 'S' (aka 'const int *const (*)[]') is not allowed}} |
| 492 |
(void) const_cast<Q>(s); |
| 493 |
// expected-error@-1 {{const_cast from 'S' (aka 'const int *const (*)[]') to 'Q' (aka 'const int *const (*)[3]') is not allowed}} |
| 494 |
(void) const_cast<Q2>(s); |
| 495 |
// expected-error@-1 {{const_cast from 'S' (aka 'const int *const (*)[]') to 'Q2' (aka 'const int *const (*)[3]') is not allowed}} |
| 496 |
(void) const_cast<T>(s); |
| 497 |
(void) const_cast<S>(t); |
| 498 |
(void) const_cast<T>(q); |
| 499 |
// expected-error@-1 {{const_cast from 'Q' (aka 'const int *const (*)[3]') to 'T' (aka 'const int *(*)[]') is not allowed}} |
| 500 |
(void) const_cast<Q>(t); |
| 501 |
// expected-error@-1 {{const_cast from 'T' (aka 'const int *(*)[]') to 'Q' (aka 'const int *const (*)[3]') is not allowed}} |
| 502 |
|
| 503 |
(void) reinterpret_cast<P>(q); |
| 504 |
// expected-error@-1 {{reinterpret_cast from 'Q' (aka 'const int *const (*)[3]') to 'P' (aka 'int *(*)[3]') casts away qualifiers}} |
| 505 |
(void) reinterpret_cast<P>(q2); |
| 506 |
// expected-error@-1 {{reinterpret_cast from 'Q2' (aka 'const int *const (*)[3]') to 'P' (aka 'int *(*)[3]') casts away qualifiers}} |
| 507 |
(void) reinterpret_cast<Q>(p); |
| 508 |
(void) reinterpret_cast<Q2>(p); |
| 509 |
(void) reinterpret_cast<S>(p); |
| 510 |
(void) reinterpret_cast<P>(s); |
| 511 |
// expected-error@-1 {{reinterpret_cast from 'S' (aka 'const int *const (*)[]') to 'P' (aka 'int *(*)[3]') casts away qualifiers}} |
| 512 |
(void) reinterpret_cast<S>(q); |
| 513 |
(void) reinterpret_cast<S>(q2); |
| 514 |
(void) reinterpret_cast<Q>(s); |
| 515 |
(void) reinterpret_cast<Q2>(s); |
| 516 |
(void) reinterpret_cast<T>(s); |
| 517 |
// expected-error@-1 {{reinterpret_cast from 'S' (aka 'const int *const (*)[]') to 'T' (aka 'const int *(*)[]') casts away qualifiers}} |
| 518 |
(void) reinterpret_cast<S>(t); |
| 519 |
(void) reinterpret_cast<T>(q); |
| 520 |
// expected-error@-1 {{reinterpret_cast from 'Q' (aka 'const int *const (*)[3]') to 'T' (aka 'const int *(*)[]') casts away qualifiers}} |
| 521 |
(void) reinterpret_cast<Q>(t); |
| 522 |
} |
| 523 |
|
| 524 |
namespace swift_17882 { |
| 525 |
typedef const char P[72]; |
| 526 |
typedef int *Q; |
| 527 |
void f(P &pr, P *pp) { |
| 528 |
(void) reinterpret_cast<const Q&>(pr); |
| 529 |
(void) reinterpret_cast<const Q*>(pp); |
| 530 |
} |
| 531 |
|
| 532 |
struct X {}; |
| 533 |
typedef const volatile int A[1][2][3]; |
| 534 |
typedef int *const X::*volatile *B1; |
| 535 |
typedef int *const X::* *B2; |
| 536 |
typedef int *X::* volatile *B3; |
| 537 |
typedef volatile int *(*const B4)[4]; |
| 538 |
void f(A *a) { |
| 539 |
(void) reinterpret_cast<B1*>(a); |
| 540 |
(void) reinterpret_cast<B2*>(a); |
| 541 |
// expected-error@-1 {{ISO C++ does not allow reinterpret_cast from 'A *' (aka 'const volatile int (*)[1][2][3]') to 'B2 *' (aka 'int *const X::***') because it casts away qualifiers, even though the source and destination types are unrelated}} |
| 542 |
(void) reinterpret_cast<B3*>(a); |
| 543 |
// expected-error@-1 {{ISO C++ does not allow reinterpret_cast from 'A *' (aka 'const volatile int (*)[1][2][3]') to 'B3 *' (aka 'int *X::*volatile **') because it casts away qualifiers, even though the source and destination types are unrelated}} |
| 544 |
(void) reinterpret_cast<B4*>(a); |
| 545 |
} |
| 546 |
} |
| 547 |
} // namespace cwg330 |
| 548 |
|
| 549 |
namespace cwg331 { // cwg331: 11 |
| 550 |
struct A { |
| 551 |
A(volatile A&); // #cwg331-A-ctor |
| 552 |
}; |
| 553 |
const A a; |
| 554 |
// expected-error@-1 {{no matching constructor for initialization of 'const A'}} |
| 555 |
// expected-note@#cwg331-A-ctor {{candidate constructor not viable: requires 1 argument, but 0 were provided}} |
| 556 |
const A b(a); |
| 557 |
// expected-error@-1 {{no matching constructor for initialization of 'const A'}} |
| 558 |
// expected-note@#cwg331-A-ctor {{candidate constructor not viable: 1st argument ('const A') would lose const qualifier}} |
| 559 |
} // namespace cwg331 |
| 560 |
|
| 561 |
namespace cwg332 { // cwg332: dup 577 |
| 562 |
void f(volatile void); |
| 563 |
// expected-error@-1 {{'void' as parameter must not have type qualifiers}} |
| 564 |
// cxx20-23-warning@-2 {{volatile-qualified parameter type 'volatile void' is deprecated}} |
| 565 |
void g(const void); |
| 566 |
// expected-error@-1 {{'void' as parameter must not have type qualifiers}} |
| 567 |
void h(int n, volatile void); |
| 568 |
// expected-error@-1 {{'void' must be the first and only parameter if specified}} |
| 569 |
// cxx20-23-warning@-2 {{volatile-qualified parameter type 'volatile void' is deprecated}} |
| 570 |
} // namespace cwg332 |
| 571 |
|
| 572 |
namespace cwg333 { // cwg333: 2.7 |
| 573 |
int n = 0; |
| 574 |
int f(int(n)); |
| 575 |
int g((int(n))); |
| 576 |
int h = f(g); |
| 577 |
} // namespace cwg333 |
| 578 |
|
| 579 |
namespace cwg334 { // cwg334: 2.7 |
| 580 |
template<typename T> void f() { |
| 581 |
T x; |
| 582 |
f((x, 123)); |
| 583 |
} |
| 584 |
struct S { |
| 585 |
friend S operator,(S, int); |
| 586 |
friend void f(S); |
| 587 |
}; |
| 588 |
template void f<S>(); |
| 589 |
} // namespace cwg334 |
| 590 |
|
| 591 |
// cwg335: sup 820 |
| 592 |
|
| 593 |
namespace cwg336 { // cwg336: 2.7 |
| 594 |
namespace Pre { |
| 595 |
template<class T1> class A { |
| 596 |
template<class T2> class B { |
| 597 |
template<class T3> void mf1(T3); |
| 598 |
void mf2(); |
| 599 |
}; |
| 600 |
}; |
| 601 |
template<> template<class X> class A<int>::B {}; // #cwg336-B |
| 602 |
template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {} |
| 603 |
// expected-error@-1 {{out-of-line definition of 'mf1' does not match any declaration in 'cwg336::Pre::A<int>::B<double>'}} |
| 604 |
// expected-note@#cwg336-B {{defined here}} |
| 605 |
template<class Y> template<> void A<Y>::B<double>::mf2() {} |
| 606 |
// expected-error@-1 {{nested name specifier 'A<Y>::B<double>' for declaration does not refer into a class, class template or class template partial specialization}} |
| 607 |
} |
| 608 |
namespace Post { |
| 609 |
template<class T1> class A { |
| 610 |
template<class T2> class B { |
| 611 |
template<class T3> void mf1(T3); |
| 612 |
void mf2(); |
| 613 |
}; |
| 614 |
}; |
| 615 |
template<> template<class X> class A<int>::B { |
| 616 |
template<class T> void mf1(T); |
| 617 |
}; |
| 618 |
template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {} |
| 619 |
// FIXME: This diagnostic isn't very good. |
| 620 |
template<class Y> template<> void A<Y>::B<double>::mf2() {} |
| 621 |
// expected-error@-1 {{nested name specifier 'A<Y>::B<double>' for declaration does not refer into a class, class template or class template partial specialization}} |
| 622 |
} |
| 623 |
} // namespace cwg336 |
| 624 |
|
| 625 |
namespace cwg337 { // cwg337: 2.7 |
| 626 |
template<typename T> void f(T (*)[1]); |
| 627 |
template<typename T> int &f(...); |
| 628 |
|
| 629 |
struct A { virtual ~A() = 0; }; |
| 630 |
int &r = f<A>(0); |
| 631 |
|
| 632 |
// FIXME: The language rules here are completely broken. We cannot determine |
| 633 |
// whether an incomplete type is abstract. See CWG1640, which will probably |
| 634 |
// supersede this one and remove this rule. |
| 635 |
struct B; |
| 636 |
int &s = f<B>(0); |
| 637 |
// expected-error@-1 {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'void'}} |
| 638 |
struct B { virtual ~B() = 0; }; |
| 639 |
} // namespace cwg337 |
| 640 |
|
| 641 |
// cwg338: dup 1884 |
| 642 |
|
| 643 |
namespace cwg339 { // cwg339: 2.8 |
| 644 |
template <int I> struct A { static const int value = I; }; |
| 645 |
|
| 646 |
char xxx(int); |
| 647 |
char (&xxx(float))[2]; |
| 648 |
|
| 649 |
template<class T> A<sizeof(xxx((T)0))> f(T) {} // #cwg339-f |
| 650 |
|
| 651 |
void test() { |
| 652 |
A<1> a = f(0); |
| 653 |
A<2> b = f(0.0f); |
| 654 |
A<3> c = f("foo"); |
| 655 |
// expected-error@-1 {{no matching function}} |
| 656 |
// expected-note@#cwg339-f {{candidate}} |
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
char f(int); |
| 661 |
int f(...); |
| 662 |
|
| 663 |
template <class T> struct conv_int { |
| 664 |
static const bool value = sizeof(f(T())) == 1; |
| 665 |
}; |
| 666 |
|
| 667 |
template <class T> bool conv_int2(A<sizeof(f(T()))> p); |
| 668 |
|
| 669 |
template<typename T> A<sizeof(f(T()))> make_A(); |
| 670 |
|
| 671 |
static_assert(conv_int<char>::value, ""); |
| 672 |
bool b = conv_int2<char>(A<1>()); |
| 673 |
A<1> c = make_A<char>(); |
| 674 |
} // namespace cwg339 |
| 675 |
|
| 676 |
namespace cwg340 { // cwg340: 2.7 |
| 677 |
struct A { A(int); }; |
| 678 |
struct B { B(A, A, int); }; |
| 679 |
int x, y; |
| 680 |
B b(A(x), A(y), 3); |
| 681 |
} // namespace cwg340 |
| 682 |
|
| 683 |
namespace cwg341 { // cwg341: sup 1708 |
| 684 |
namespace A { |
| 685 |
int n; |
| 686 |
extern "C" int &cwg341_a = n; // #cwg341_a |
| 687 |
} |
| 688 |
namespace B { |
| 689 |
extern "C" int &cwg341_a = cwg341_a; |
| 690 |
// expected-error@-1 {{redefinition of 'cwg341_a'}} |
| 691 |
// expected-note@#cwg341_a {{previous definition is here}} |
| 692 |
} |
| 693 |
extern "C" void cwg341_b(); // #cwg341_b |
| 694 |
} |
| 695 |
int cwg341_a; |
| 696 |
// expected-error@-1 {{declaration of 'cwg341_a' in global scope conflicts with declaration with C language linkage}} |
| 697 |
// expected-note@#cwg341_a {{declared with C language linkage here}} |
| 698 |
int cwg341_b; |
| 699 |
// expected-error@-1 {{declaration of 'cwg341_b' in global scope conflicts with declaration with C language linkage}} |
| 700 |
// expected-note@#cwg341_b {{declared with C language linkage here}} |
| 701 |
int cwg341_c; // #cwg341_c |
| 702 |
int cwg341_d; // #cwg341_d |
| 703 |
namespace cwg341 { |
| 704 |
extern "C" int cwg341_c; |
| 705 |
// expected-error@-1 {{declaration of 'cwg341_c' with C language linkage conflicts with declaration in global scope}} |
| 706 |
// expected-note@#cwg341_c {{declared in global scope here}} |
| 707 |
extern "C" void cwg341_d(); |
| 708 |
// expected-error@-1 {{declaration of 'cwg341_d' with C language linkage conflicts with declaration in global scope}} |
| 709 |
// expected-note@#cwg341_d {{declared in global scope here}} |
| 710 |
|
| 711 |
namespace A { extern "C" int cwg341_e; } // #cwg341_e |
| 712 |
namespace B { extern "C" void cwg341_e(); } |
| 713 |
// expected-error@-1 {{redefinition of 'cwg341_e' as different kind of symbol}} |
| 714 |
// expected-note@#cwg341_e {{previous definition is here}} |
| 715 |
} // namespace cwg341 |
| 716 |
|
| 717 |
// cwg342: na |
| 718 |
|
| 719 |
namespace cwg343 { // cwg343: no |
| 720 |
// FIXME: dup 1710 |
| 721 |
template<typename T> struct A { |
| 722 |
template<typename U> struct B {}; |
| 723 |
}; |
| 724 |
// FIXME: In these contexts, the 'template' keyword is optional. |
| 725 |
template<typename T> struct C : public A<T>::B<T> { |
| 726 |
// expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}} |
| 727 |
C() : A<T>::B<T>() {} |
| 728 |
// expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}} |
| 729 |
}; |
| 730 |
} // namespace cwg343 |
| 731 |
|
| 732 |
namespace cwg344 { // cwg344: dup 1435 |
| 733 |
struct A { inline virtual ~A(); }; |
| 734 |
struct B { friend A::~A(); }; |
| 735 |
} // namespace cwg344 |
| 736 |
|
| 737 |
namespace cwg345 { // cwg345: 2.7 |
| 738 |
struct A { |
| 739 |
struct X {}; |
| 740 |
int X; // #cwg345-int-X |
| 741 |
}; |
| 742 |
struct B { |
| 743 |
struct X {}; |
| 744 |
}; |
| 745 |
template <class T> void f(T t) { typename T::X x; } |
| 746 |
// expected-error@-1 {{typename specifier refers to non-type member 'X' in 'cwg345::A'}} |
| 747 |
// expected-note@#cwg345-f-a {{in instantiation of function template specialization 'cwg345::f<cwg345::A>' requested here}} |
| 748 |
// expected-note@#cwg345-int-X {{referenced member 'X' is declared here}} |
| 749 |
void f(A a, B b) { |
| 750 |
f(b); |
| 751 |
f(a); // #cwg345-f-a |
| 752 |
} |
| 753 |
} // namespace cwg345 |
| 754 |
|
| 755 |
// cwg346: na |
| 756 |
|
| 757 |
namespace cwg347 { // cwg347: 2.7 |
| 758 |
struct base { |
| 759 |
struct nested; |
| 760 |
static int n; |
| 761 |
static void f(); |
| 762 |
void g(); |
| 763 |
}; |
| 764 |
|
| 765 |
struct derived : base {}; // #cwg347-derived |
| 766 |
|
| 767 |
struct derived::nested {}; |
| 768 |
// expected-error@-1 {{no struct named 'nested' in 'cwg347::derived'}} |
| 769 |
int derived::n; |
| 770 |
// expected-error@-1 {{no member named 'n' in 'cwg347::derived'}} |
| 771 |
void derived::f() {} |
| 772 |
// expected-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'cwg347::derived'}} |
| 773 |
// expected-note@#cwg347-derived {{defined here}} |
| 774 |
void derived::g() {} |
| 775 |
// expected-error@-1 {{out-of-line definition of 'g' does not match any declaration in 'cwg347::derived'}} |
| 776 |
// expected-note@#cwg347-derived {{defined here}} |
| 777 |
} // namespace cwg347 |
| 778 |
|
| 779 |
// cwg348: na |
| 780 |
|
| 781 |
namespace cwg349 { // cwg349: no |
| 782 |
struct A { |
| 783 |
template <class T> operator T ***() { |
| 784 |
int ***p = 0; |
| 785 |
return p; |
| 786 |
// cxx98-20-error@-1 {{cannot initialize return object of type 'const int ***' with an lvalue of type 'int ***'}} |
| 787 |
// since-cxx23-error@-2 {{cannot initialize return object of type 'const int ***' with an rvalue of type 'int ***'}} |
| 788 |
// expected-note@#cwg349-p1 {{in instantiation of function template specialization 'cwg349::A::operator const int ***<const int>' requested here}} |
| 789 |
} |
| 790 |
}; |
| 791 |
|
| 792 |
// FIXME: This is valid. |
| 793 |
A a; |
| 794 |
const int *const *const *p1 = a; // #cwg349-p1 |
| 795 |
|
| 796 |
struct B { |
| 797 |
template <class T> operator T ***() { |
| 798 |
const int ***p = 0; |
| 799 |
return p; |
| 800 |
} |
| 801 |
}; |
| 802 |
|
| 803 |
// FIXME: This is invalid. |
| 804 |
B b; |
| 805 |
const int *const *const *p2 = b; |
| 806 |
} // namespace cwg349 |
| 807 |
|
| 808 |
// cwg351: na |
| 809 |
|
| 810 |
namespace cwg352 { // cwg352: 2.8 |
| 811 |
namespace example1 { |
| 812 |
namespace A { |
| 813 |
enum E {}; |
| 814 |
template<typename R, typename A> void foo(E, R (*)(A)); // #cwg352-foo |
| 815 |
} |
| 816 |
|
| 817 |
template<typename T> void arg(T); |
| 818 |
template<typename T> int arg(T) = delete; // #cwg352-deleted |
| 819 |
// cxx98-error@-1 {{deleted function definitions are a C++11 extension}} |
| 820 |
|
| 821 |
void f(A::E e) { |
| 822 |
foo(e, &arg); |
| 823 |
// expected-error@-1 {{no matching function for call to 'foo'}} |
| 824 |
// expected-note@#cwg352-foo {{candidate template ignored: couldn't infer template argument 'R'}} |
| 825 |
|
| 826 |
using A::foo; |
| 827 |
foo<int, int>(e, &arg); |
| 828 |
// expected-error@-1 {{attempt to use a deleted function}} |
| 829 |
// expected-note@#cwg352-deleted {{'arg<int>' has been explicitly marked deleted here}} |
| 830 |
} |
| 831 |
|
| 832 |
int arg(int); |
| 833 |
|
| 834 |
void g(A::E e) { |
| 835 |
foo(e, &arg); |
| 836 |
// expected-error@-1 {{no matching function for call to 'foo'}} |
| 837 |
// expected-note@#cwg352-foo {{candidate template ignored: couldn't infer template argument 'R'}} |
| 838 |
|
| 839 |
using A::foo; |
| 840 |
foo<int, int>(e, &arg); // ok, uses non-template |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
namespace contexts { |
| 845 |
template<int I> void f1(int (&)[I]); |
| 846 |
template<int I> void f2(int (&)[I+1]); // #cwg352-f2 |
| 847 |
template<int I> void f3(int (&)[I+1], int (&)[I]); |
| 848 |
void f() { |
| 849 |
int a[4]; |
| 850 |
int b[3]; |
| 851 |
f1(a); |
| 852 |
f2(a); |
| 853 |
// expected-error@-1 {{no matching function for call to 'f2'}} |
| 854 |
// expected-note@#cwg352-f2 {{candidate template ignored: couldn't infer template argument 'I'}} |
| 855 |
f3(a, b); |
| 856 |
} |
| 857 |
|
| 858 |
template<int I> struct S {}; |
| 859 |
template<int I> void g1(S<I>); |
| 860 |
template<int I> void g2(S<I+1>); // #cwg352-g2 |
| 861 |
template<int I> void g3(S<I+1>, S<I>); |
| 862 |
void g() { |
| 863 |
S<4> a; |
| 864 |
S<3> b; |
| 865 |
g1(a); |
| 866 |
g2(a); |
| 867 |
// expected-error@-1 {{no matching function for call to 'g2'}} |
| 868 |
// expected-note@#cwg352-g2 {{candidate template ignored: couldn't infer template argument 'I'}} |
| 869 |
g3(a, b); |
| 870 |
} |
| 871 |
|
| 872 |
template<typename T> void h1(T = 0); // #cwg352-h1 |
| 873 |
template<typename T> void h2(T, T = 0); |
| 874 |
void h() { |
| 875 |
h1(); |
| 876 |
// expected-error@-1 {{no matching function for call to 'h1'}} |
| 877 |
// expected-note@#cwg352-h1 {{candidate template ignored: couldn't infer template argument 'T'}} |
| 878 |
h1(0); |
| 879 |
h1<int>(); |
| 880 |
h2(0); |
| 881 |
} |
| 882 |
|
| 883 |
template<typename T> int tmpl(T); |
| 884 |
template<typename R, typename A> void i1(R (*)(A)); // #cwg352-i1 |
| 885 |
template<typename R, typename A> void i2(R, A, R (*)(A)); // #cwg352-i2 |
| 886 |
void i() { |
| 887 |
extern int single(int); |
| 888 |
i1(single); |
| 889 |
i2(0, 0, single); |
| 890 |
|
| 891 |
extern int ambig(float), ambig(int); |
| 892 |
i1(ambig); |
| 893 |
// expected-error@-1 {{no matching function for call to 'i1'}} |
| 894 |
// expected-note@#cwg352-i1 {{candidate template ignored: couldn't infer template argument 'R'}} |
| 895 |
i2(0, 0, ambig); |
| 896 |
|
| 897 |
extern void no_match(float), no_match(int); |
| 898 |
i1(no_match); |
| 899 |
// expected-error@-1 {{no matching function for call to 'i1'}} |
| 900 |
// expected-note@#cwg352-i1 {{candidate template ignored: couldn't infer template argument 'R'}} |
| 901 |
i2(0, 0, no_match); |
| 902 |
// expected-error@-1 {{no matching function for call to 'i2'}} |
| 903 |
// expected-note@#cwg352-i2 {{candidate function [with R = int, A = int] not viable: no overload of 'no_match' matching 'int (*)(int)' for 3rd argument}} |
| 904 |
|
| 905 |
i1(tmpl); |
| 906 |
// expected-error@-1 {{no matching function for call to 'i1'}} |
| 907 |
// expected-note@#cwg352-i1 {{candidate template ignored: couldn't infer template argument 'R'}} |
| 908 |
i2(0, 0, tmpl); |
| 909 |
} |
| 910 |
} |
| 911 |
|
| 912 |
template<typename T> struct is_int; |
| 913 |
template<> struct is_int<int> {}; |
| 914 |
|
| 915 |
namespace example2 { |
| 916 |
template<typename T> int f(T (*p)(T)) { is_int<T>(); } |
| 917 |
int g(int); |
| 918 |
int g(char); |
| 919 |
int i = f(g); |
| 920 |
} |
| 921 |
|
| 922 |
namespace example3 { |
| 923 |
template<typename T> int f(T, T (*p)(T)) { is_int<T>(); } |
| 924 |
int g(int); |
| 925 |
char g(char); |
| 926 |
int i = f(1, g); |
| 927 |
} |
| 928 |
|
| 929 |
namespace example4 { |
| 930 |
template <class T> int f(T, T (*p)(T)) { is_int<T>(); } |
| 931 |
char g(char); |
| 932 |
template <class T> T g(T); |
| 933 |
int i = f(1, g); |
| 934 |
} |
| 935 |
|
| 936 |
namespace example5 { |
| 937 |
template<int I> class A {}; |
| 938 |
template<int I> void g(A<I+1>); // #cwg352-g |
| 939 |
template<int I> void f(A<I>, A<I+1>); |
| 940 |
void h(A<1> a1, A<2> a2) { |
| 941 |
g(a1); |
| 942 |
// expected-error@-1 {{no matching function for call to 'g'}} |
| 943 |
// expected-note@#cwg352-g {{candidate template ignored: couldn't infer template argument 'I'}} |
| 944 |
g<0>(a1); |
| 945 |
f(a1, a2); |
| 946 |
} |
| 947 |
} |
| 948 |
} // namespace cwg352 |
| 949 |
|
| 950 |
// cwg353 needs an IRGen test. |
| 951 |
|
| 952 |
namespace cwg354 { // cwg354: 3.1 c++11 |
| 953 |
// FIXME: Should we allow this in C++98 too? |
| 954 |
struct S {}; |
| 955 |
|
| 956 |
template<int*> struct ptr {}; // #cwg354-ptr |
| 957 |
ptr<0> p0; // #cwg354-p0 |
| 958 |
// cxx98-error@#cwg354-p0 {{non-type template argument does not refer to any declaration}} |
| 959 |
// cxx98-note@#cwg354-ptr {{template parameter is declared here}} |
| 960 |
// cxx11-14-error@#cwg354-p0 {{null non-type template argument must be cast to template parameter type 'int *'}} |
| 961 |
// cxx11-14-note@#cwg354-ptr {{template parameter is declared here}} |
| 962 |
// since-cxx17-error@#cwg354-p0 {{conversion from 'int' to 'int *' is not allowed in a converted constant expression}} |
| 963 |
// since-cxx17-note@#cwg354-ptr {{template parameter is declared here}} |
| 964 |
ptr<(int*)0> p1; |
| 965 |
// cxx98-error@-1 {{non-type template argument does not refer to any declaration}} |
| 966 |
// cxx98-note@#cwg354-ptr {{template parameter is declared here}} |
| 967 |
ptr<(float*)0> p2; // #cwg354-p2 |
| 968 |
// cxx98-error@#cwg354-p2 {{non-type template argument does not refer to any declaration}} |
| 969 |
// cxx98-note@#cwg354-ptr {{template parameter is declared here}} |
| 970 |
// cxx11-14-error@#cwg354-p2 {{null non-type template argument of type 'float *' does not match template parameter of type 'int *'}} |
| 971 |
// cxx11-14-note@#cwg354-ptr {{template parameter is declared here}} |
| 972 |
// since-cxx17-error@#cwg354-p2 {{value of type 'float *' is not implicitly convertible to 'int *'}} |
| 973 |
// since-cxx17-note@#cwg354-ptr {{template parameter is declared here}} |
| 974 |
ptr<(int S::*)0> p3; // #cwg354-p3 |
| 975 |
// cxx98-error@#cwg354-p3 {{non-type template argument does not refer to any declaration}} |
| 976 |
// cxx98-note@#cwg354-ptr {{template parameter is declared here}} |
| 977 |
// cxx11-14-error@#cwg354-p3 {{null non-type template argument of type 'int S::*' does not match template parameter of type 'int *'}} |
| 978 |
// cxx11-14-note@#cwg354-ptr {{template parameter is declared here}} |
| 979 |
// since-cxx17-error@#cwg354-p3 {{value of type 'int S::*' is not implicitly convertible to 'int *'}} |
| 980 |
// since-cxx17-note@#cwg354-ptr {{template parameter is declared here}} |
| 981 |
|
| 982 |
template<int*> int both(); // #cwg354-both-int-ptr |
| 983 |
template<int> int both(); // #cwg354-both-int |
| 984 |
int b0 = both<0>(); |
| 985 |
int b1 = both<(int*)0>(); |
| 986 |
// cxx98-error@-1 {{no matching function for call to 'both'}} |
| 987 |
// cxx98-note@#cwg354-both-int-ptr {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}} |
| 988 |
// cxx98-note@#cwg354-both-int {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}} |
| 989 |
|
| 990 |
template<int S::*> struct ptr_mem {}; // #cwg354-ptr_mem |
| 991 |
ptr_mem<0> m0; // #cwg354-m0 |
| 992 |
// cxx98-error@#cwg354-m0 {{non-type template argument of type 'int' cannot be converted to a value of type 'int S::*'}} |
| 993 |
// cxx98-note@#cwg354-ptr_mem {{template parameter is declared here}} |
| 994 |
// cxx11-14-error@#cwg354-m0 {{null non-type template argument must be cast to template parameter type 'int S::*'}} |
| 995 |
// cxx11-14-note@#cwg354-ptr_mem {{template parameter is declared here}} |
| 996 |
// since-cxx17-error@#cwg354-m0 {{conversion from 'int' to 'int S::*' is not allowed in a converted constant expression}} |
| 997 |
// since-cxx17-note@#cwg354-ptr_mem {{template parameter is declared here}} |
| 998 |
ptr_mem<(int S::*)0> m1; |
| 999 |
// cxx98-error@-1 {{non-type template argument is not a pointer to member constant}} |
| 1000 |
ptr_mem<(float S::*)0> m2; // #cwg354-m2 |
| 1001 |
// cxx98-error@#cwg354-m2 {{non-type template argument of type 'float S::*' cannot be converted to a value of type 'int S::*'}} |
| 1002 |
// cxx98-note@#cwg354-ptr_mem {{template parameter is declared here}} |
| 1003 |
// cxx11-14-error@#cwg354-m2 {{null non-type template argument of type 'float S::*' does not match template parameter of type 'int S::*'}} |
| 1004 |
// cxx11-14-note@#cwg354-ptr_mem {{template parameter is declared here}} |
| 1005 |
// since-cxx17-error@#cwg354-m2 {{value of type 'float S::*' is not implicitly convertible to 'int S::*'}} |
| 1006 |
// since-cxx17-note@#cwg354-ptr_mem {{template parameter is declared here}} |
| 1007 |
ptr_mem<(int *)0> m3; // #cwg354-m3 |
| 1008 |
// cxx98-error@#cwg354-m3 {{non-type template argument of type 'int *' cannot be converted to a value of type 'int S::*'}} |
| 1009 |
// cxx98-note@#cwg354-ptr_mem {{template parameter is declared here}} |
| 1010 |
// cxx11-14-error@#cwg354-m3 {{null non-type template argument of type 'int *' does not match template parameter of type 'int S::*'}} |
| 1011 |
// cxx11-14-note@#cwg354-ptr_mem {{template parameter is declared here}} |
| 1012 |
// since-cxx17-error@#cwg354-m3 {{value of type 'int *' is not implicitly convertible to 'int S::*'}} |
| 1013 |
// since-cxx17-note@#cwg354-ptr_mem {{template parameter is declared here}} |
| 1014 |
} // namespace cwg354 |
| 1015 |
|
| 1016 |
struct cwg355_S; // cwg355: 2.7 |
| 1017 |
struct ::cwg355_S {}; |
| 1018 |
// expected-warning@-1 {{extra qualification on member 'cwg355_S'}} |
| 1019 |
namespace cwg355 { |
| 1020 |
struct ::cwg355_S s; |
| 1021 |
} // namespace cwg355 |
| 1022 |
|
| 1023 |
// cwg356: na |
| 1024 |
|
| 1025 |
namespace cwg357 { // cwg357: 2.7 |
| 1026 |
template<typename T> struct A { // #cwg357-A |
| 1027 |
void f() const; // #cwg357-f |
| 1028 |
}; |
| 1029 |
template<typename T> void A<T>::f() {} |
| 1030 |
// expected-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'cwg357::A<T>'}} |
| 1031 |
// expected-note@#cwg357-A {{defined here}} |
| 1032 |
// expected-note@#cwg357-f {{member declaration does not match because it is const qualified}} |
| 1033 |
|
| 1034 |
struct B { // #cwg357-B |
| 1035 |
template<typename T> void f(); |
| 1036 |
}; |
| 1037 |
template<typename T> void B::f() const {} |
| 1038 |
// expected-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'cwg357::B'}} |
| 1039 |
// expected-note@#cwg357-B {{defined here}} |
| 1040 |
} // namespace cwg357 |
| 1041 |
|
| 1042 |
namespace cwg358 { // cwg358: 2.7 |
| 1043 |
extern "C" void cwg358_f(); |
| 1044 |
namespace N { |
| 1045 |
int var; |
| 1046 |
extern "C" void cwg358_f() { var = 10; } |
| 1047 |
} |
| 1048 |
} // namespace cwg358 |
| 1049 |
|
| 1050 |
namespace cwg359 { // cwg359: 3.3 |
| 1051 |
// Note, the example in the DR is wrong; it doesn't contain an anonymous |
| 1052 |
// union. |
| 1053 |
struct E { |
| 1054 |
union { |
| 1055 |
struct { |
| 1056 |
int x; |
| 1057 |
} s; |
| 1058 |
} v; |
| 1059 |
|
| 1060 |
union { |
| 1061 |
struct { |
| 1062 |
// expected-error@-1 {{anonymous types declared in an anonymous union are an extension}} |
| 1063 |
int x; |
| 1064 |
} s; |
| 1065 |
|
| 1066 |
struct S { |
| 1067 |
// expected-error@-1 {{types cannot be declared in an anonymous union}} |
| 1068 |
int x; |
| 1069 |
} t; |
| 1070 |
|
| 1071 |
union { |
| 1072 |
// expected-error@-1 {{anonymous types declared in an anonymous union are an extension}} |
| 1073 |
int u; |
| 1074 |
}; |
| 1075 |
}; |
| 1076 |
}; |
| 1077 |
} // namespace cwg359 |
| 1078 |
|
| 1079 |
namespace cwg360 { // cwg360: 2.8 |
| 1080 |
struct A { |
| 1081 |
int foo(); |
| 1082 |
int bar(); |
| 1083 |
|
| 1084 |
protected: |
| 1085 |
int baz(); |
| 1086 |
}; |
| 1087 |
|
| 1088 |
struct B : A { |
| 1089 |
private: |
| 1090 |
using A::foo; // #cwg360-using-foo |
| 1091 |
protected: |
| 1092 |
using A::bar; // #cwg360-using-bar |
| 1093 |
public: |
| 1094 |
using A::baz; |
| 1095 |
}; |
| 1096 |
|
| 1097 |
int main() { |
| 1098 |
int foo = B().foo(); |
| 1099 |
// expected-error@-1 {{'foo' is a private member of 'cwg360::B'}} |
| 1100 |
// expected-note@#cwg360-using-foo {{declared private here}} |
| 1101 |
int bar = B().bar(); |
| 1102 |
// expected-error@-1 {{'bar' is a protected member of 'cwg360::B'}} |
| 1103 |
// expected-note@#cwg360-using-bar {{declared protected here}} |
| 1104 |
int baz = B().baz(); |
| 1105 |
} |
| 1106 |
} // namespace cwg360 |
| 1107 |
|
| 1108 |
// cwg362: na |
| 1109 |
// cwg363: na |
| 1110 |
|
| 1111 |
namespace cwg364 { // cwg364: 2.7 |
| 1112 |
struct S { |
| 1113 |
static void f(int); |
| 1114 |
void f(char); |
| 1115 |
}; |
| 1116 |
|
| 1117 |
void g() { |
| 1118 |
S::f('a'); |
| 1119 |
// expected-error@-1 {{call to non-static member function without an object argument}} |
| 1120 |
S::f(0); |
| 1121 |
} |
| 1122 |
} // namespace cwg364 |
| 1123 |
|
| 1124 |
namespace cwg366 { // cwg366: 2.7 |
| 1125 |
#if "foo" // expected-error {{invalid token at start of a preprocessor expression}} |
| 1126 |
#endif |
| 1127 |
} // namespace cwg366 |
| 1128 |
|
| 1129 |
namespace cwg367 { // cwg367: 2.7 |
| 1130 |
static_assert(__enable_constant_folding(true ? throw 0 : 4), ""); |
| 1131 |
// expected-error@-1 {{expression is not an integral constant expression}} |
| 1132 |
static_assert(__enable_constant_folding(true ? 4 : throw 0), ""); |
| 1133 |
static_assert(__enable_constant_folding(true ? *new int : 4), ""); |
| 1134 |
// expected-error@-1 {{expression is not an integral constant expression}} |
| 1135 |
// expected-note@-2 {{read of uninitialized object is not allowed in a constant expression}} |
| 1136 |
static_assert(__enable_constant_folding(true ? 4 : *new int), ""); |
| 1137 |
} // namespace cwg367 |
| 1138 |
|
| 1139 |
namespace cwg368 { // cwg368: 3.6 |
| 1140 |
template<typename T, T> struct S {}; // #cwg368-S |
| 1141 |
template<typename T> int f(S<T, T()> *); |
| 1142 |
// expected-error@-1 {{template argument for non-type template parameter is treated as function type 'T ()'}} |
| 1143 |
// expected-note@#cwg368-S {{template parameter is declared here}} |
| 1144 |
template<typename T> int g(S<T, (T())> *); // #cwg368-g |
| 1145 |
template<typename T> int g(S<T, true ? T() : T()> *); // #cwg368-g-2 |
| 1146 |
struct X {}; |
| 1147 |
int n = g<X>(0); // #cwg368-g-call |
| 1148 |
// cxx98-17-error@#cwg368-g-call {{no matching function for call to 'g'}} |
| 1149 |
// cxx98-17-note@#cwg368-g {{candidate template ignored: substitution failure [with T = X]: a non-type template parameter cannot have type 'X' before C++20}} |
| 1150 |
// cxx98-17-note@#cwg368-g-2 {{candidate template ignored: substitution failure [with T = X]: a non-type template parameter cannot have type 'X' before C++20}} |
| 1151 |
// cxx20-23-error@#cwg368-g-call {{call to 'g' is ambiguous}} |
| 1152 |
// cxx20-23-note@#cwg368-g {{candidate function [with T = cwg368::X]}} |
| 1153 |
// cxx20-23-note@#cwg368-g-2 {{candidate function [with T = cwg368::X]}} |
| 1154 |
} // namespace cwg368 |
| 1155 |
|
| 1156 |
// cwg370: na |
| 1157 |
|
| 1158 |
namespace cwg372 { // cwg372: no |
| 1159 |
namespace example1 { |
| 1160 |
template<typename T> struct X { |
| 1161 |
protected: |
| 1162 |
typedef T Type; // #cwg372-ex1-Type |
| 1163 |
}; |
| 1164 |
template<typename T> struct Y {}; |
| 1165 |
|
| 1166 |
// FIXME: These two are valid; deriving from T1<T> gives Z1 access to |
| 1167 |
// the protected member T1<T>::Type. |
| 1168 |
template<typename T, |
| 1169 |
template<typename> class T1, |
| 1170 |
template<typename> class T2> struct Z1 : |
| 1171 |
T1<T>, |
| 1172 |
T2<typename T1<T>::Type> {}; |
| 1173 |
// expected-error@-1 {{'Type' is a protected member of 'cwg372::example1::X<int>'}} |
| 1174 |
// expected-note@#cwg372-z1 {{in instantiation of template class 'cwg372::example1::Z1<int, cwg372::example1::X, cwg372::example1::Y>' requested here}} |
| 1175 |
// expected-note@#cwg372-ex1-Type {{declared protected here}} |
| 1176 |
|
| 1177 |
template<typename T, |
| 1178 |
template<typename> class T1, |
| 1179 |
template<typename> class T2> struct Z2 : |
| 1180 |
T2<typename T1<T>::Type>, |
| 1181 |
// expected-error@-1 {{'Type' is a protected member of 'cwg372::example1::X<int>'}} |
| 1182 |
// expected-note@#cwg372-z2 {{in instantiation of template class 'cwg372::example1::Z2<int, cwg372::example1::X, cwg372::example1::Y>' requested here}} |
| 1183 |
// expected-note@#cwg372-ex1-Type {{declared protected here}} |
| 1184 |
T1<T> {}; |
| 1185 |
|
| 1186 |
Z1<int, X, Y> z1; // #cwg372-z1 |
| 1187 |
Z2<int, X, Y> z2; // #cwg372-z2 |
| 1188 |
} |
| 1189 |
|
| 1190 |
namespace example2 { |
| 1191 |
struct X { |
| 1192 |
private: |
| 1193 |
typedef int Type; // #cwg372-ex2-Type |
| 1194 |
}; |
| 1195 |
template<typename T> struct A { |
| 1196 |
typename T::Type t; |
| 1197 |
// expected-error@-1 {{'Type' is a private member of 'cwg372::example2::X'}} |
| 1198 |
// expected-note@#cwg372-ax {{in instantiation of template class 'cwg372::example2::A<cwg372::example2::X>' requested here}} |
| 1199 |
// expected-note@#cwg372-ex2-Type {{declared private here}} |
| 1200 |
}; |
| 1201 |
A<X> ax; // #cwg372-ax |
| 1202 |
} |
| 1203 |
|
| 1204 |
namespace example3 { |
| 1205 |
struct A { |
| 1206 |
protected: |
| 1207 |
typedef int N; // #cwg372-N |
| 1208 |
}; |
| 1209 |
|
| 1210 |
template<typename T> struct B {}; |
| 1211 |
template<typename U> struct C : U, B<typename U::N> {}; |
| 1212 |
// expected-error@-1 {{'N' is a protected member of 'cwg372::example3::A'}} |
| 1213 |
// expected-note@#cwg372-x {{in instantiation of template class 'cwg372::example3::C<cwg372::example3::A>' requested here}} |
| 1214 |
// expected-note@#cwg372-N {{declared protected here}} |
| 1215 |
template<typename U> struct D : B<typename U::N>, U {}; |
| 1216 |
// expected-error@-1 {{'N' is a protected member of 'cwg372::example3::A'}} |
| 1217 |
// expected-note@#cwg372-y {{in instantiation of template class 'cwg372::example3::D<cwg372::example3::A>' requested here}} |
| 1218 |
// expected-note@#cwg372-N {{declared protected here}} |
| 1219 |
|
| 1220 |
C<A> x; // #cwg372-x |
| 1221 |
D<A> y; // #cwg372-y |
| 1222 |
} |
| 1223 |
|
| 1224 |
namespace example4 { |
| 1225 |
class A { |
| 1226 |
class B {}; |
| 1227 |
friend class X; |
| 1228 |
}; |
| 1229 |
|
| 1230 |
struct X : A::B { |
| 1231 |
A::B mx; |
| 1232 |
class Y { |
| 1233 |
A::B my; |
| 1234 |
}; |
| 1235 |
}; |
| 1236 |
} |
| 1237 |
|
| 1238 |
// FIXME: This is valid: deriving from A gives D access to A::B |
| 1239 |
namespace std_example { |
| 1240 |
class A { |
| 1241 |
protected: |
| 1242 |
struct B {}; // #cwg372-B-std |
| 1243 |
}; |
| 1244 |
struct D : A::B, A {}; |
| 1245 |
// expected-error@-1 {{'B' is a protected member of 'cwg372::std_example::A'}} |
| 1246 |
// expected-note@#cwg372-B-std {{declared protected here}} |
| 1247 |
} |
| 1248 |
|
| 1249 |
// FIXME: This is valid: deriving from A::B gives access to A::B! |
| 1250 |
namespace badwolf { |
| 1251 |
class A { |
| 1252 |
protected: |
| 1253 |
struct B; // #cwg372-B |
| 1254 |
}; |
| 1255 |
struct A::B : A {}; |
| 1256 |
struct C : A::B {}; |
| 1257 |
// expected-error@-1 {{'B' is a protected member of 'cwg372::badwolf::A'}} |
| 1258 |
// expected-note@#cwg372-B {{declared protected here}} |
| 1259 |
} |
| 1260 |
} // namespace cwg372 |
| 1261 |
|
| 1262 |
namespace cwg373 { // cwg373: 5 |
| 1263 |
namespace X { int cwg373; } |
| 1264 |
struct cwg373 { // #cwg373-struct |
| 1265 |
void f() { |
| 1266 |
using namespace cwg373::X; |
| 1267 |
int k = cwg373; |
| 1268 |
// expected-error@-1 {{'cwg373' does not refer to a value}} |
| 1269 |
// expected-note@#cwg373-struct {{declared here}} |
| 1270 |
namespace Y = cwg373::X; |
| 1271 |
k = Y::cwg373; |
| 1272 |
} |
| 1273 |
}; |
| 1274 |
|
| 1275 |
struct A { struct B {}; }; // #cwg373-A |
| 1276 |
namespace X = A::B; |
| 1277 |
// expected-error@-1 {{expected namespace name}} |
| 1278 |
// expected-note@#cwg373-A {{'A' declared here}} |
| 1279 |
using namespace A::B; |
| 1280 |
// expected-error@-1 {{expected namespace name}} |
| 1281 |
// expected-note@#cwg373-A {{'A' declared here}} |
| 1282 |
} // namespace cwg373 |
| 1283 |
|
| 1284 |
namespace cwg374 { // cwg374: 7 |
| 1285 |
// NB 2.9 c++11 |
| 1286 |
namespace N { |
| 1287 |
template<typename T> void f(); |
| 1288 |
template<typename T> struct A { void f(); }; |
| 1289 |
} |
| 1290 |
template<> void N::f<char>() {} |
| 1291 |
template<> void N::A<char>::f() {} |
| 1292 |
template<> struct N::A<int> {}; |
| 1293 |
} // namespace cwg374 |
| 1294 |
|
| 1295 |
// cwg375: dup 345 |
| 1296 |
// cwg376: na |
| 1297 |
|
| 1298 |
namespace cwg377 { // cwg377: 2.7 |
| 1299 |
enum E { |
| 1300 |
// expected-error@-1 {{enumeration values exceed range of largest integer}} |
| 1301 |
a = -__LONG_LONG_MAX__ - 1, |
| 1302 |
// cxx98-error@-1 {{'long long' is a C++11 extension}} |
| 1303 |
b = 2 * (unsigned long long)__LONG_LONG_MAX__ |
| 1304 |
// cxx98-error@-1 {{'long long' is a C++11 extension}} |
| 1305 |
// cxx98-error@-2 {{'long long' is a C++11 extension}} |
| 1306 |
}; |
| 1307 |
} // namespace cwg377 |
| 1308 |
|
| 1309 |
// cwg378: dup 276 |
| 1310 |
// cwg379: na |
| 1311 |
|
| 1312 |
namespace cwg381 { // cwg381: 2.7 |
| 1313 |
struct A { |
| 1314 |
int a; |
| 1315 |
}; |
| 1316 |
struct B : virtual A {}; |
| 1317 |
struct C : B {}; |
| 1318 |
struct D : B {}; |
| 1319 |
struct E : public C, public D {}; |
| 1320 |
struct F : public A {}; |
| 1321 |
void f() { |
| 1322 |
E e; |
| 1323 |
e.B::a = 0; |
| 1324 |
/* expected-error@-1 {{ambiguous conversion from derived class 'E' to base class 'B': |
| 1325 |
struct cwg381::E -> C -> B |
| 1326 |
struct cwg381::E -> D -> B}} */ |
| 1327 |
F f; |
| 1328 |
f.A::a = 1; |
| 1329 |
} |
| 1330 |
} // namespace cwg381 |
| 1331 |
|
| 1332 |
namespace cwg382 { // cwg382: 2.7 c++11 |
| 1333 |
// FIXME: Should we allow this in C++98 mode? |
| 1334 |
struct A { typedef int T; }; |
| 1335 |
typename A::T t; |
| 1336 |
// cxx98-error@-1 {{'typename' outside of a template is a C++11 extension}} |
| 1337 |
typename cwg382::A a; |
| 1338 |
// cxx98-error@-1 {{'typename' outside of a template is a C++11 extension}} |
| 1339 |
typename A b; |
| 1340 |
// expected-error@-1 {{expected a qualified name after 'typename'}} |
| 1341 |
} // namespace cwg382 |
| 1342 |
|
| 1343 |
namespace cwg383 { // cwg383: 2.7 |
| 1344 |
struct A { A &operator=(const A&); }; |
| 1345 |
struct B { ~B(); }; |
| 1346 |
union C { C &operator=(const C&); }; |
| 1347 |
union D { ~D(); }; |
| 1348 |
static_assert(!__is_pod(A) && !__is_pod(B) && !__is_pod(C) && !__is_pod(D), ""); |
| 1349 |
} // namespace cwg383 |
| 1350 |
|
| 1351 |
namespace cwg384 { // cwg384: 2.7 |
| 1352 |
namespace N1 { |
| 1353 |
template<typename T> struct Base {}; |
| 1354 |
template<typename T> struct X { |
| 1355 |
struct Y : public Base<T> { |
| 1356 |
Y operator+(int) const; |
| 1357 |
}; |
| 1358 |
Y f(unsigned i) { return Y() + i; } |
| 1359 |
}; |
| 1360 |
} |
| 1361 |
|
| 1362 |
namespace N2 { |
| 1363 |
struct Z {}; |
| 1364 |
template<typename T> int *operator+(T, unsigned); |
| 1365 |
} |
| 1366 |
|
| 1367 |
int main() { |
| 1368 |
N1::X<N2::Z> v; |
| 1369 |
v.f(0); |
| 1370 |
} |
| 1371 |
} // namespace cwg384 |
| 1372 |
|
| 1373 |
namespace cwg385 { // cwg385: 2.8 |
| 1374 |
struct A { protected: void f(); }; |
| 1375 |
struct B : A { using A::f; }; |
| 1376 |
struct C : A { void g(B b) { b.f(); } }; |
| 1377 |
void h(B b) { b.f(); } |
| 1378 |
|
| 1379 |
struct D { int n; }; // #cwg385-n |
| 1380 |
struct E : protected D {}; // #cwg385-E |
| 1381 |
struct F : E { friend int i(E); }; |
| 1382 |
int i(E e) { return e.n; } |
| 1383 |
// expected-error@-1 {{'n' is a protected member of 'cwg385::D'}} |
| 1384 |
// expected-note@#cwg385-E {{constrained by protected inheritance here}} |
| 1385 |
// expected-note@#cwg385-n {{member is declared here}} |
| 1386 |
} // namespace cwg385 |
| 1387 |
|
| 1388 |
namespace cwg386 { // cwg386: no |
| 1389 |
namespace example1 { |
| 1390 |
namespace N1 { |
| 1391 |
// Binds name 'f' in N1. Target scope is N1. |
| 1392 |
template<typename T> void f( T* x ) { |
| 1393 |
// ... other stuff ... |
| 1394 |
delete x; |
| 1395 |
} |
| 1396 |
} |
| 1397 |
|
| 1398 |
namespace N2 { |
| 1399 |
// Bind name 'f' in N2. When a single search find this declaration, |
| 1400 |
// it's replaced with N1::f declaration. |
| 1401 |
using N1::f; |
| 1402 |
|
| 1403 |
// According to _N4988_.[dcl.meaning]/3.3: |
| 1404 |
// `f<int>` is not a qualified-id, so its target scope is N2. |
| 1405 |
// `f<int>` is a template-id, so 'f' undergoes (unqualified) lookup. |
| 1406 |
// Search performed by unqualified lookup finds N1::f via using-declaration, |
| 1407 |
// but this result is not considered, because it's not nominable in N2, |
| 1408 |
// which is because its target scope is N1. |
| 1409 |
// So unqualified lookup doesn't find anything, making this declaration ill-formed. |
| 1410 |
template<> void f<int>( int* ); |
| 1411 |
// expected-error@-1 {{no function template matches function template specialization 'f'}} |
| 1412 |
|
| 1413 |
class Test { |
| 1414 |
~Test() { } |
| 1415 |
// According to _N4988_.[dcl.meaning]/2.2: |
| 1416 |
// `f<>` is a template-id and not a template declaration, |
| 1417 |
// so its terminal name 'f' undergoes (unqualified) lookup. |
| 1418 |
// Search in N2 performed by unqualified lookup finds |
| 1419 |
// (single) N1::f declaration via using-declaration. |
| 1420 |
// N1::f is replaced with N1::f<> specialization after deduction, |
| 1421 |
// and this is the result of the unqualified lookup. |
| 1422 |
// This friend declaration correspond to the result of the lookup. |
| 1423 |
// All lookup results target the same scope, which is N1, |
| 1424 |
// so target scope of this friend declaration is also N1. |
| 1425 |
// FIXME: This is well-formed. |
| 1426 |
friend void f<>( Test* x ); |
| 1427 |
// expected-error@-1 {{no function template matches function template specialization 'f'}} |
| 1428 |
}; |
| 1429 |
} |
| 1430 |
} // namespace example1 |
| 1431 |
|
| 1432 |
namespace example2 { |
| 1433 |
namespace N1 { |
| 1434 |
// Binds name 'f' in N1. Target scope is N1. |
| 1435 |
void f(); // #cwg386-ex2-N1-f |
| 1436 |
} |
| 1437 |
|
| 1438 |
namespace N2 { |
| 1439 |
// Bind name 'f' in N2. When a single search finds this declaration, |
| 1440 |
// it's replaced with N1::f declaration. |
| 1441 |
using N1::f; // #cwg386-ex2-using |
| 1442 |
class A { |
| 1443 |
// According to _N4988_.[dcl.meaning]/2.2: |
| 1444 |
// `N2::f` is a qualified-id, so its terminal name 'f' undergoes (qualified) lookup. |
| 1445 |
// Search in N2 performed by qualified lookup finds N1::f via using-declaration, |
| 1446 |
// which is the (only) result of qualified lookup. |
| 1447 |
// This friend declaration corresponds to the result of the lookup. |
| 1448 |
// All lookup results target the same scope, which is N1, |
| 1449 |
// so target scope of this friend declaration is also N1. |
| 1450 |
// FIXME: This is well-formed. |
| 1451 |
friend void N2::f(); |
| 1452 |
// expected-error@-1 {{cannot befriend target of using declaration}} |
| 1453 |
// expected-note@#cwg386-ex2-N1-f {{target of using declaration}} |
| 1454 |
// expected-note@#cwg386-ex2-using {{using declaration}} |
| 1455 |
}; |
| 1456 |
} |
| 1457 |
} // namespace example2 |
| 1458 |
} // namespace cwg386 |
| 1459 |
|
| 1460 |
namespace cwg387 { // cwg387: 2.8 |
| 1461 |
namespace old { |
| 1462 |
template<typename T> class number { |
| 1463 |
number(int); // #cwg387-number-ctor |
| 1464 |
friend number gcd(number &x, number &y) {} |
| 1465 |
}; |
| 1466 |
|
| 1467 |
void g() { |
| 1468 |
number<double> a(3); |
| 1469 |
// expected-error@-1 {{calling a private constructor of class 'cwg387::old::number<double>'}} |
| 1470 |
// expected-note@#cwg387-number-ctor {{implicitly declared private here}} |
| 1471 |
number<double> b(4); |
| 1472 |
// expected-error@-1 {{calling a private constructor of class 'cwg387::old::number<double>'}} |
| 1473 |
// expected-note@#cwg387-number-ctor {{implicitly declared private here}} |
| 1474 |
a = gcd(a, b); |
| 1475 |
b = gcd(3, 4); |
| 1476 |
// expected-error@-1 {{use of undeclared identifier 'gcd'}} |
| 1477 |
} |
| 1478 |
} |
| 1479 |
|
| 1480 |
namespace newer { |
| 1481 |
template <typename T> class number { |
| 1482 |
public: |
| 1483 |
number(int); |
| 1484 |
friend number gcd(number x, number y) { return 0; } |
| 1485 |
}; |
| 1486 |
|
| 1487 |
void g() { |
| 1488 |
number<double> a(3), b(4); |
| 1489 |
a = gcd(a, b); |
| 1490 |
b = gcd(3, 4); |
| 1491 |
// expected-error@-1 {{use of undeclared identifier 'gcd'}} |
| 1492 |
} |
| 1493 |
} |
| 1494 |
} // namespace cwg387 |
| 1495 |
|
| 1496 |
// FIXME: cwg388 needs libc++abi test |
| 1497 |
|
| 1498 |
namespace cwg389 { // cwg389: no |
| 1499 |
struct S { |
| 1500 |
typedef struct {} A; |
| 1501 |
typedef enum {} B; |
| 1502 |
typedef struct {} const C; // #cwg389-C |
| 1503 |
typedef enum {} const D; // #cwg389-D |
| 1504 |
}; |
| 1505 |
template<typename> struct T {}; |
| 1506 |
|
| 1507 |
struct WithLinkage1 {}; |
| 1508 |
enum WithLinkage2 {}; |
| 1509 |
typedef struct {} *WithLinkage3a, WithLinkage3b; |
| 1510 |
typedef enum {} WithLinkage4a, *WithLinkage4b; |
| 1511 |
typedef S::A WithLinkage5; |
| 1512 |
typedef const S::B WithLinkage6; |
| 1513 |
typedef int WithLinkage7; |
| 1514 |
typedef void (*WithLinkage8)(WithLinkage2 WithLinkage1::*, WithLinkage5 *); |
| 1515 |
typedef T<WithLinkage5> WithLinkage9; |
| 1516 |
|
| 1517 |
typedef struct {} *WithoutLinkage1; // #cwg389-no-link-1 |
| 1518 |
typedef enum {} const WithoutLinkage2; // #cwg389-no-link-2 |
| 1519 |
// These two types don't have linkage even though they are externally visible |
| 1520 |
// and the ODR requires them to be merged across TUs. |
| 1521 |
typedef S::C WithoutLinkage3; |
| 1522 |
typedef S::D WithoutLinkage4; |
| 1523 |
typedef void (*WithoutLinkage5)(int (WithoutLinkage3::*)(char)); |
| 1524 |
|
| 1525 |
#if __cplusplus >= 201103L |
| 1526 |
// This has linkage even though its template argument does not. |
| 1527 |
// FIXME: This is probably a defect. |
| 1528 |
typedef T<WithoutLinkage1> WithLinkage10; |
| 1529 |
#else |
| 1530 |
typedef int WithLinkage10; // dummy |
| 1531 |
|
| 1532 |
typedef T<WithLinkage1> GoodArg1; |
| 1533 |
typedef T<WithLinkage2> GoodArg2; |
| 1534 |
typedef T<WithLinkage3a> GoodArg3a; |
| 1535 |
typedef T<WithLinkage3b> GoodArg3b; |
| 1536 |
typedef T<WithLinkage4a> GoodArg4a; |
| 1537 |
typedef T<WithLinkage4b> GoodArg4b; |
| 1538 |
typedef T<WithLinkage5> GoodArg5; |
| 1539 |
typedef T<WithLinkage6> GoodArg6; |
| 1540 |
typedef T<WithLinkage7> GoodArg7; |
| 1541 |
typedef T<WithLinkage8> GoodArg8; |
| 1542 |
typedef T<WithLinkage9> GoodArg9; |
| 1543 |
|
| 1544 |
typedef T<WithoutLinkage1> BadArg1; |
| 1545 |
// expected-error@-1 {{template argument uses unnamed type}} |
| 1546 |
// expected-note@#cwg389-no-link-1 {{unnamed type used in template argument was declared here}} |
| 1547 |
typedef T<WithoutLinkage2> BadArg2; |
| 1548 |
// expected-error@-1 {{template argument uses unnamed type}} |
| 1549 |
// expected-note@#cwg389-no-link-2 {{unnamed type used in template argument was declared here}} |
| 1550 |
typedef T<WithoutLinkage3> BadArg3; |
| 1551 |
// expected-error@-1 {{template argument uses unnamed type}} |
| 1552 |
// expected-note@#cwg389-C {{unnamed type used in template argument was declared here}} |
| 1553 |
typedef T<WithoutLinkage4> BadArg4; |
| 1554 |
// expected-error@-1 {{template argument uses unnamed type}} |
| 1555 |
// expected-note@#cwg389-D {{unnamed type used in template argument was declared here}} |
| 1556 |
typedef T<WithoutLinkage5> BadArg5; |
| 1557 |
// expected-error@-1 {{template argument uses unnamed type}} |
| 1558 |
// expected-note@#cwg389-C {{unnamed type used in template argument was declared here}} |
| 1559 |
#endif |
| 1560 |
|
| 1561 |
extern WithLinkage1 withLinkage1; |
| 1562 |
extern WithLinkage2 withLinkage2; |
| 1563 |
extern WithLinkage3a withLinkage3a; |
| 1564 |
extern WithLinkage3b withLinkage3b; |
| 1565 |
extern WithLinkage4a withLinkage4a; |
| 1566 |
extern WithLinkage4b withLinkage4b; |
| 1567 |
extern WithLinkage5 withLinkage5; |
| 1568 |
extern WithLinkage6 withLinkage6; |
| 1569 |
extern WithLinkage7 withLinkage7; |
| 1570 |
extern WithLinkage8 withLinkage8; |
| 1571 |
extern WithLinkage9 withLinkage9; |
| 1572 |
extern WithLinkage10 withLinkage10; |
| 1573 |
|
| 1574 |
// FIXME: These are all ill-formed. |
| 1575 |
extern WithoutLinkage1 withoutLinkage1; |
| 1576 |
extern WithoutLinkage2 withoutLinkage2; |
| 1577 |
extern WithoutLinkage3 withoutLinkage3; |
| 1578 |
extern WithoutLinkage4 withoutLinkage4; |
| 1579 |
extern WithoutLinkage5 withoutLinkage5; |
| 1580 |
|
| 1581 |
// OK, extern "C". |
| 1582 |
extern "C" { |
| 1583 |
extern WithoutLinkage1 cwg389_withoutLinkage1; |
| 1584 |
extern WithoutLinkage2 cwg389_withoutLinkage2; |
| 1585 |
extern WithoutLinkage3 cwg389_withoutLinkage3; |
| 1586 |
extern WithoutLinkage4 cwg389_withoutLinkage4; |
| 1587 |
extern WithoutLinkage5 cwg389_withoutLinkage5; |
| 1588 |
} |
| 1589 |
|
| 1590 |
// OK, defined. |
| 1591 |
WithoutLinkage1 withoutLinkageDef1; |
| 1592 |
WithoutLinkage2 withoutLinkageDef2 = WithoutLinkage2(); |
| 1593 |
WithoutLinkage3 withoutLinkageDef3 = {}; |
| 1594 |
WithoutLinkage4 withoutLinkageDef4 = WithoutLinkage4(); |
| 1595 |
WithoutLinkage5 withoutLinkageDef5; |
| 1596 |
|
| 1597 |
void use(const void *); |
| 1598 |
void use_all() { |
| 1599 |
use(&withLinkage1); use(&withLinkage2); use(&withLinkage3a); use(&withLinkage3b); |
| 1600 |
use(&withLinkage4a); use(&withLinkage4b); use(&withLinkage5); use(&withLinkage6); |
| 1601 |
use(&withLinkage7); use(&withLinkage8); use(&withLinkage9); use(&withLinkage10); |
| 1602 |
|
| 1603 |
use(&withoutLinkage1); use(&withoutLinkage2); use(&withoutLinkage3); |
| 1604 |
use(&withoutLinkage4); use(&withoutLinkage5); |
| 1605 |
|
| 1606 |
use(&cwg389_withoutLinkage1); use(&cwg389_withoutLinkage2); |
| 1607 |
use(&cwg389_withoutLinkage3); use(&cwg389_withoutLinkage4); |
| 1608 |
use(&cwg389_withoutLinkage5); |
| 1609 |
|
| 1610 |
use(&withoutLinkageDef1); use(&withoutLinkageDef2); use(&withoutLinkageDef3); |
| 1611 |
use(&withoutLinkageDef4); use(&withoutLinkageDef5); |
| 1612 |
} |
| 1613 |
|
| 1614 |
void local() { |
| 1615 |
// FIXME: This is ill-formed. |
| 1616 |
extern WithoutLinkage1 withoutLinkageLocal; |
| 1617 |
} |
| 1618 |
} // namespace cwg389 |
| 1619 |
|
| 1620 |
namespace cwg390 { // cwg390: 3.3 |
| 1621 |
template<typename T> |
| 1622 |
struct A { |
| 1623 |
A() { f(); } |
| 1624 |
// 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 'cwg390::A<int>'}} |
| 1625 |
// expected-note@#cwg390-A-int {{in instantiation of member function 'cwg390::A<int>::A' requested here}} |
| 1626 |
// expected-note@#cwg390-f {{'f' declared here}} |
| 1627 |
virtual void f() = 0; // #cwg390-f |
| 1628 |
virtual ~A() = 0; |
| 1629 |
}; |
| 1630 |
template<typename T> A<T>::~A() { T::error; } |
| 1631 |
// expected-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}} |
| 1632 |
// expected-note@#cwg390-A-int {{in instantiation of member function 'cwg390::A<int>::~A' requested here}} |
| 1633 |
template<typename T> void A<T>::f() { T::error; } // ok, not odr-used |
| 1634 |
struct B : A<int> { // #cwg390-A-int |
| 1635 |
void f() {} |
| 1636 |
} b; |
| 1637 |
} // namespace cwg390 |
| 1638 |
|
| 1639 |
namespace cwg391 { // cwg391: 2.8 c++11 |
| 1640 |
// FIXME: Should this apply to C++98 too? |
| 1641 |
class A { A(const A&); }; // #cwg391-A |
| 1642 |
A fa(); |
| 1643 |
const A &a = fa(); |
| 1644 |
// cxx98-error@-1 {{C++98 requires an accessible copy constructor for class 'cwg391::A' when binding a reference to a temporary; was private}} |
| 1645 |
// cxx98-note@#cwg391-A {{implicitly declared private here}} |
| 1646 |
|
| 1647 |
struct B { B(const B&) = delete; }; // #cwg391-B |
| 1648 |
// cxx98-error@-1 {{deleted function definitions are a C++11 extension}} |
| 1649 |
B fb(); |
| 1650 |
const B &b = fb(); |
| 1651 |
// cxx98-error@-1 {{copying variable of type 'B' invokes deleted constructor}} |
| 1652 |
// cxx98-note@#cwg391-B {{'B' has been explicitly marked deleted here}} |
| 1653 |
|
| 1654 |
template<typename T> |
| 1655 |
struct C { |
| 1656 |
C(const C&) { T::error; } |
| 1657 |
}; |
| 1658 |
C<int> fc(); |
| 1659 |
const C<int> &c = fc(); |
| 1660 |
} // namespace cwg391 |
| 1661 |
|
| 1662 |
// cwg392 is in cwg392.cpp |
| 1663 |
|
| 1664 |
namespace cwg393 { // cwg393: 2.7 |
| 1665 |
template <typename T> |
| 1666 |
struct S {}; |
| 1667 |
|
| 1668 |
void f1(S<int (*)[]>); |
| 1669 |
void f2(S<int (&)[]>); |
| 1670 |
void g(int(*S<int>::*)[]); |
| 1671 |
|
| 1672 |
template<typename T> |
| 1673 |
void sp_assert_convertible( T* ) {} |
| 1674 |
|
| 1675 |
template<typename T, typename U> |
| 1676 |
void h() { |
| 1677 |
T (*p) [] = (U(*)[])0; |
| 1678 |
sp_assert_convertible<T[]>( (U(*)[])0 ); |
| 1679 |
} |
| 1680 |
} // namespace cwg393 |
| 1681 |
|
| 1682 |
// cwg394: na |
| 1683 |
|
| 1684 |
namespace cwg395 { // cwg395: 3.0 |
| 1685 |
struct S { |
| 1686 |
template <typename T, int N>(&operator T())[N]; |
| 1687 |
// expected-error@-1 {{cannot specify any part of a return type in the declaration of a conversion function}} |
| 1688 |
template <typename T, int N> operator(T (&)[N])(); |
| 1689 |
// expected-error@-1 {{expected ')'}} |
| 1690 |
// expected-note@-2 {{to match this '('}} |
| 1691 |
// expected-error@-3 {{a type specifier is required for all declarations}} |
| 1692 |
template <typename T> operator T *() const { return 0; } |
| 1693 |
template <typename T, typename U> operator T U::*() const { return 0; } |
| 1694 |
template <typename T, typename U> operator T (U::*)()() const { return 0; } |
| 1695 |
// expected-error@-1 {{a type specifier is required for all declarations}} |
| 1696 |
// expected-error@-2 {{conversion function cannot have any parameters}} |
| 1697 |
// expected-error@-3 {{cannot specify any part of a return type in the declaration of a conversion function}} |
| 1698 |
// expected-error@-4 {{conversion function cannot convert to a function type}} |
| 1699 |
|
| 1700 |
}; |
| 1701 |
|
| 1702 |
struct null1_t { |
| 1703 |
template <class T, class U> struct ptr_mem_fun_t { |
| 1704 |
typedef T (U::*type)(); |
| 1705 |
}; |
| 1706 |
|
| 1707 |
template <class T, class U> |
| 1708 |
operator typename ptr_mem_fun_t<T, U>::type() const { // #cwg395-conv-func |
| 1709 |
return 0; |
| 1710 |
} |
| 1711 |
} null1; |
| 1712 |
int (S::*p)() = null1; |
| 1713 |
// expected-error@-1 {{no viable conversion from 'struct null1_t' to 'int (S::*)()'}} |
| 1714 |
// expected-note@#cwg395-conv-func {{candidate template ignored: couldn't infer template argument 'T'}} |
| 1715 |
|
| 1716 |
template <typename T> using id = T; |
| 1717 |
// cxx98-error@-1 {{alias declarations are a C++11 extension}} |
| 1718 |
|
| 1719 |
struct T { |
| 1720 |
template <typename T, int N> operator id<T[N]> &(); |
| 1721 |
template <typename T, typename U> operator id<T (U::*)()>() const; |
| 1722 |
}; |
| 1723 |
|
| 1724 |
struct null2_t { |
| 1725 |
template<class T, class U> using ptr_mem_fun_t = T (U::*)(); |
| 1726 |
// cxx98-error@-1 {{alias declarations are a C++11 extension}} |
| 1727 |
template<class T, class U> operator ptr_mem_fun_t<T, U>() const { return 0; }; |
| 1728 |
} null2; |
| 1729 |
int (S::*q)() = null2; |
| 1730 |
} // namespace cwg395 |
| 1731 |
|
| 1732 |
namespace cwg396 { // cwg396: 3.0 |
| 1733 |
void f() { |
| 1734 |
auto int a(); |
| 1735 |
// since-cxx11-error@-1 {{'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases}} |
| 1736 |
// expected-error@-2 {{illegal storage class on function}} |
| 1737 |
int (i); // #cwg396-i |
| 1738 |
auto int (i); |
| 1739 |
// since-cxx11-error@-1 {{'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases}} |
| 1740 |
// expected-error@-2 {{redefinition of 'i'}} |
| 1741 |
// expected-note@#cwg396-i {{previous definition is here}} |
| 1742 |
} |
| 1743 |
} // namespace cwg396 |
| 1744 |
|
| 1745 |
// cwg397: sup 1823 |
| 1746 |
|
| 1747 |
namespace cwg398 { // cwg398: 2.7 |
| 1748 |
namespace example1 { |
| 1749 |
struct S { |
| 1750 |
static int const I = 42; |
| 1751 |
}; |
| 1752 |
template <int N> struct X {}; |
| 1753 |
template <typename T> void f(X<T::I> *) {} |
| 1754 |
template <typename T> void f(X<T::J> *) {} |
| 1755 |
void foo() { f<S>(0); } |
| 1756 |
} |
| 1757 |
|
| 1758 |
namespace example2 { |
| 1759 |
template <int I> struct X {}; |
| 1760 |
template <template <class T> class> struct Z {}; |
| 1761 |
template <class T> void f(typename T::Y *) {} // #cwg398-f |
| 1762 |
template <class T> void g(X<T::N> *) {} // #cwg398-g |
| 1763 |
template <class T> void h(Z<T::template TT> *) {} // #cwg398-h |
| 1764 |
struct A {}; |
| 1765 |
struct B { |
| 1766 |
int Y; |
| 1767 |
}; |
| 1768 |
struct C { |
| 1769 |
typedef int N; |
| 1770 |
}; |
| 1771 |
struct D { |
| 1772 |
typedef int TT; |
| 1773 |
}; |
| 1774 |
|
| 1775 |
void test() { |
| 1776 |
f<A>(0); |
| 1777 |
// expected-error@-1 {{no matching function for call to 'f'}} |
| 1778 |
// expected-note@#cwg398-f {{candidate template ignored: substitution failure [with T = A]: no type named 'Y' in 'cwg398::example2::A'}} |
| 1779 |
f<B>(0); |
| 1780 |
// expected-error@-1 {{no matching function for call to 'f'}} |
| 1781 |
// expected-note@#cwg398-f {{candidate template ignored: substitution failure [with T = B]: typename specifier refers to non-type member 'Y' in 'cwg398::example2::B'}} |
| 1782 |
g<C>(0); |
| 1783 |
// expected-error@-1 {{no matching function for call to 'g'}} |
| 1784 |
// expected-note@#cwg398-g {{candidate template ignored: substitution failure [with T = C]: missing 'typename' prior to dependent type name 'C::N'}} |
| 1785 |
h<D>(0); |
| 1786 |
// expected-error@-1 {{no matching function for call to 'h'}} |
| 1787 |
// expected-note@#cwg398-h {{candidate template ignored: substitution failure [with T = D]: 'TT' following the 'template' keyword does not refer to a template}} |
| 1788 |
} |
| 1789 |
} |
| 1790 |
} // namespace cwg398 |
| 1791 |
|
| 1792 |
namespace cwg399 { // cwg399: 11 |
| 1793 |
// NB: reuse cwg244 test |
| 1794 |
struct B {}; // #cwg399-B |
| 1795 |
struct D : B {}; |
| 1796 |
|
| 1797 |
D D_object; |
| 1798 |
typedef B B_alias; |
| 1799 |
B* B_ptr = &D_object; |
| 1800 |
|
| 1801 |
void f() { |
| 1802 |
D_object.~B(); |
| 1803 |
// expected-error@-1 {{destructor type 'B' in object destruction expression does not match the type 'D' of the object being destroyed}} |
| 1804 |
// expected-note@#cwg399-B {{type 'B' found by destructor name lookup}} |
| 1805 |
D_object.B::~B(); |
| 1806 |
D_object.D::~B(); // FIXME: Missing diagnostic for this. |
| 1807 |
B_ptr->~B(); |
| 1808 |
B_ptr->~B_alias(); |
| 1809 |
B_ptr->B_alias::~B(); |
| 1810 |
B_ptr->B_alias::~B_alias(); |
| 1811 |
B_ptr->cwg399::~B(); |
| 1812 |
// expected-error@-1 {{no member named '~B' in namespace 'cwg399'}} |
| 1813 |
B_ptr->cwg399::~B_alias(); |
| 1814 |
// expected-error@-1 {{no member named '~B' in namespace 'cwg399'}} |
| 1815 |
} |
| 1816 |
|
| 1817 |
template<typename T, typename U> |
| 1818 |
void f(T *B_ptr, U D_object) { |
| 1819 |
D_object.~B(); // FIXME: Missing diagnostic for this. |
| 1820 |
D_object.B::~B(); |
| 1821 |
D_object.D::~B(); // FIXME: Missing diagnostic for this. |
| 1822 |
B_ptr->~B(); |
| 1823 |
B_ptr->~B_alias(); |
| 1824 |
B_ptr->B_alias::~B(); |
| 1825 |
B_ptr->B_alias::~B_alias(); |
| 1826 |
B_ptr->cwg399::~B(); |
| 1827 |
// expected-error@-1 {{'cwg399' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}} |
| 1828 |
B_ptr->cwg399::~B_alias(); |
| 1829 |
// expected-error@-1 {{'cwg399' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}} |
| 1830 |
} |
| 1831 |
template void f<B, D>(B*, D); |
| 1832 |
|
| 1833 |
namespace N { |
| 1834 |
template<typename T> struct E {}; |
| 1835 |
typedef E<int> F; |
| 1836 |
} |
| 1837 |
void g(N::F f) { |
| 1838 |
typedef N::F G; // #cwg399-G |
| 1839 |
f.~G(); |
| 1840 |
f.G::~E(); |
| 1841 |
// expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}} |
| 1842 |
f.G::~F(); |
| 1843 |
// expected-error@-1 {{undeclared identifier 'F' in destructor name}} |
| 1844 |
f.G::~G(); |
| 1845 |
// This is technically ill-formed; E is looked up in 'N::' and names the |
| 1846 |
// class template, not the injected-class-name of the class. But that's |
| 1847 |
// probably a bug in the standard. |
| 1848 |
f.N::F::~E(); |
| 1849 |
// expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}} |
| 1850 |
// This is valid; we look up the second F in the same scope in which we |
| 1851 |
// found the first one, that is, 'N::'. |
| 1852 |
f.N::F::~F(); |
| 1853 |
// This is technically ill-formed; G is looked up in 'N::' and is not found. |
| 1854 |
// Rejecting this seems correct, but most compilers accept, so we do also. |
| 1855 |
f.N::F::~G(); |
| 1856 |
// expected-error@-1 {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}} |
| 1857 |
// expected-note@#cwg399-G {{type 'G' (aka 'E<int>') found by destructor name lookup}} |
| 1858 |
} |
| 1859 |
|
| 1860 |
// Bizarrely, compilers perform lookup in the scope for qualified destructor |
| 1861 |
// names, if the nested-name-specifier is non-dependent. Ensure we diagnose |
| 1862 |
// this. |
| 1863 |
namespace QualifiedLookupInScope { |
| 1864 |
namespace N { |
| 1865 |
template <typename> struct S { struct Inner {}; }; |
| 1866 |
} |
| 1867 |
template <typename U> void f(typename N::S<U>::Inner *p) { |
| 1868 |
typedef typename N::S<U>::Inner T; |
| 1869 |
p->::cwg399::QualifiedLookupInScope::N::S<U>::Inner::~T(); |
| 1870 |
// expected-error@-1 {{no type named 'T' in 'cwg399::QualifiedLookupInScope::N::S<int>'}} |
| 1871 |
// expected-note@#cwg399-f {{in instantiation of function template specialization 'cwg399::QualifiedLookupInScope::f<int>' requested here}} |
| 1872 |
} |
| 1873 |
template void f<int>(N::S<int>::Inner *); // #cwg399-f |
| 1874 |
|
| 1875 |
template <typename U> void g(U *p) { |
| 1876 |
typedef U T; |
| 1877 |
p->T::~T(); |
| 1878 |
p->U::~T(); |
| 1879 |
p->::cwg399::QualifiedLookupInScope::N::S<int>::Inner::~T(); |
| 1880 |
// expected-error@-1 {{'T' does not refer to a type name in pseudo-destructor expression; expected the name of type 'U'}} |
| 1881 |
} |
| 1882 |
template void g(N::S<int>::Inner *); |
| 1883 |
} |
| 1884 |
} // namespace cwg399 |