| 1 |
// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected,cxx98,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors |
| 2 |
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,cxx98-11,cxx98-14,cxx98-17,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors |
| 3 |
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,cxx98-14,cxx98-17,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors |
| 4 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors |
| 5 |
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors |
| 6 |
// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors |
| 7 |
// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -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 cwg100 { // cwg100: 2.7 |
| 21 |
template<const char (*)[4]> struct A {}; // #cwg100-A |
| 22 |
template<const char (&)[4]> struct B {}; // #cwg100-B |
| 23 |
template<const char *> struct C {}; // #cwg100-C |
| 24 |
template<const char &> struct D {}; // #cwg100-D |
| 25 |
A<&"foo"> a; // #cwg100-a |
| 26 |
// cxx98-14-error@#cwg100-a {{non-type template argument does not refer to any declaration}} |
| 27 |
// cxx98-14-note@#cwg100-A {{template parameter is declared here}} |
| 28 |
// since-cxx17-error@#cwg100-a {{pointer to string literal is not allowed in a template argument}} |
| 29 |
B<"bar"> b; // #cwg100-b |
| 30 |
// cxx98-14-error@#cwg100-b {{non-type template argument does not refer to any declaration}} |
| 31 |
// cxx98-14-note@#cwg100-B {{template parameter is declared here}} |
| 32 |
// since-cxx17-error@#cwg100-b {{reference to string literal is not allowed in a template argument}} |
| 33 |
C<"baz"> c; // #cwg100-c |
| 34 |
// cxx98-14-error@#cwg100-c {{non-type template argument does not refer to any declaration}} |
| 35 |
// cxx98-14-note@#cwg100-C {{template parameter is declared here}} |
| 36 |
// since-cxx17-error@#cwg100-c {{pointer to subobject of string literal is not allowed in a template argument}} |
| 37 |
D<*"quux"> d; // #cwg100-d |
| 38 |
// cxx98-14-error@#cwg100-d {{non-type template argument does not refer to any declaration}} |
| 39 |
// cxx98-14-note@#cwg100-D {{template parameter is declared here}} |
| 40 |
// since-cxx17-error@#cwg100-d {{reference to subobject of string literal is not allowed in a template argument}} |
| 41 |
} // namespace cwg100 |
| 42 |
|
| 43 |
namespace cwg101 { // cwg101: 3.5 |
| 44 |
extern "C" void cwg101_f(); |
| 45 |
typedef unsigned size_t; |
| 46 |
namespace X { |
| 47 |
extern "C" void cwg101_f(); |
| 48 |
typedef unsigned size_t; |
| 49 |
} |
| 50 |
using X::cwg101_f; |
| 51 |
using X::size_t; |
| 52 |
extern "C" void cwg101_f(); |
| 53 |
typedef unsigned size_t; |
| 54 |
} // namespace cwg101 |
| 55 |
|
| 56 |
namespace cwg102 { // cwg102: 2.7 |
| 57 |
namespace A { |
| 58 |
template<typename T> T f(T a, T b) { return a + b; } |
| 59 |
// expected-error@-1 {{call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup}} |
| 60 |
// expected-note@#cwg102-instantiation {{in instantiation of function template specialization 'cwg102::A::f<cwg102::B::S>' requested here}} |
| 61 |
// expected-note@#cwg102-operator-plus {{'operator+' should be declared prior to the call site or in namespace 'cwg102::B'}} |
| 62 |
} |
| 63 |
namespace B { |
| 64 |
struct S {}; |
| 65 |
} |
| 66 |
B::S operator+(B::S, B::S); // #cwg102-operator-plus |
| 67 |
template B::S A::f(B::S, B::S); // #cwg102-instantiation |
| 68 |
} // namespace cwg102 |
| 69 |
|
| 70 |
// cwg103: na |
| 71 |
// cwg104: na lib |
| 72 |
// cwg105: na |
| 73 |
|
| 74 |
namespace cwg106 { // cwg106: sup 540 |
| 75 |
typedef int &r1; |
| 76 |
typedef r1 &r1; |
| 77 |
typedef const r1 r1; |
| 78 |
// expected-warning@-1 {{'const' qualifier on reference type 'r1' (aka 'int &') has no effect}} |
| 79 |
typedef const r1 &r1; |
| 80 |
// expected-warning@-1 {{'const' qualifier on reference type 'r1' (aka 'int &') has no effect}} |
| 81 |
|
| 82 |
typedef const int &r2; |
| 83 |
typedef r2 &r2; |
| 84 |
typedef const r2 r2; |
| 85 |
// expected-warning@-1 {{'const' qualifier on reference type 'r2' (aka 'const int &') has no effect}} |
| 86 |
typedef const r2 &r2; |
| 87 |
// expected-warning@-1 {{'const' qualifier on reference type 'r2' (aka 'const int &') has no effect}} |
| 88 |
} // namespace cwg106 |
| 89 |
|
| 90 |
namespace cwg107 { // cwg107: 2.7 |
| 91 |
struct S {}; |
| 92 |
extern "C" S operator+(S, S) { return S(); } |
| 93 |
} // namespace cwg107 |
| 94 |
|
| 95 |
namespace cwg108 { // cwg108: 2.9 |
| 96 |
template<typename T> struct A { |
| 97 |
struct B { typedef int X; }; |
| 98 |
B::X x; |
| 99 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'B::X' is a C++20 extension}} |
| 100 |
struct C : B { X x; }; |
| 101 |
// expected-error@-1 {{unknown type name 'X'}} |
| 102 |
}; |
| 103 |
template<> struct A<int>::B { int X; }; |
| 104 |
} // namespace cwg108 |
| 105 |
|
| 106 |
namespace cwg109 { // cwg109: 2.8 |
| 107 |
struct A { template<typename T> void f(T); }; |
| 108 |
template<typename T> struct B : T { |
| 109 |
using T::template f; |
| 110 |
// expected-error@-1 {{'template' keyword not permitted here}} |
| 111 |
using T::template f<int>; |
| 112 |
// expected-error@-1 {{'template' keyword not permitted here}} |
| 113 |
// expected-error@-2 {{using declaration cannot refer to a template specialization}} |
| 114 |
// FIXME: We shouldn't suggest using the 'template' keyword in a location where it's not valid. |
| 115 |
using T::f<int>; |
| 116 |
// expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}} |
| 117 |
// expected-error@-2 {{using declaration cannot refer to a template specialization}} |
| 118 |
void g() { this->f<int>(123); } |
| 119 |
// expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}} |
| 120 |
}; |
| 121 |
} // namespace cwg109 |
| 122 |
|
| 123 |
namespace cwg110 { // cwg110: 2.8 |
| 124 |
template <typename T> |
| 125 |
void f(T); |
| 126 |
|
| 127 |
class f {}; |
| 128 |
|
| 129 |
template <typename T> |
| 130 |
void f(T, T); |
| 131 |
|
| 132 |
class f g; |
| 133 |
void (*h)(int) = static_cast<void(*)(int)>(f); |
| 134 |
void (*i)(int, int) = static_cast<void(*)(int, int)>(f); |
| 135 |
} // namespace cwg110 |
| 136 |
|
| 137 |
namespace cwg111 { // cwg111: dup 535 |
| 138 |
struct A { A(); A(volatile A&, int = 0); A(A&, const char * = "foo"); }; |
| 139 |
struct B : A { B(); }; // #cwg111-B |
| 140 |
const B b1; |
| 141 |
B b2(b1); |
| 142 |
// expected-error@-1 {{no matching constructor for initialization of 'B'}} |
| 143 |
// expected-note@#cwg111-B {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const B') would lose const qualifier}} |
| 144 |
// expected-note@#cwg111-B {{candidate constructor not viable: requires 0 arguments, but 1 was provided}} |
| 145 |
} // namespace cwg111 |
| 146 |
|
| 147 |
namespace cwg112 { // cwg112: 3.1 |
| 148 |
struct T { int n; }; |
| 149 |
typedef T Arr[1]; |
| 150 |
|
| 151 |
const T a1[1] = {}; // #cwg112-a1 |
| 152 |
volatile T a2[1] = {}; |
| 153 |
const Arr a3 = {}; // #cwg112-a3 |
| 154 |
volatile Arr a4 = {}; |
| 155 |
template<const volatile T*> struct X {}; |
| 156 |
// FIXME: Test this somehow in C++11 and on. |
| 157 |
X<a1> x1; |
| 158 |
// cxx98-error@-1 {{non-type template argument referring to object 'a1' with internal linkage is a C++11 extension}} |
| 159 |
// cxx98-note@#cwg112-a1 {{non-type template argument refers to object here}} |
| 160 |
X<a2> x2; |
| 161 |
X<a3> x3; |
| 162 |
// cxx98-error@-1 {{non-type template argument referring to object 'a3' with internal linkage is a C++11 extension}} |
| 163 |
// cxx98-note@#cwg112-a3 {{non-type template argument refers to object here}} |
| 164 |
X<a4> x4; |
| 165 |
} // namespace cwg112 |
| 166 |
|
| 167 |
namespace cwg113 { // cwg113: 2.7 |
| 168 |
extern void (*p)(); |
| 169 |
void f() { |
| 170 |
no_such_function(); |
| 171 |
// expected-error@-1 {{use of undeclared identifier 'no_such_function'}} |
| 172 |
p(); |
| 173 |
} |
| 174 |
void g(); |
| 175 |
void (*p)() = &g; |
| 176 |
} // namespace cwg113 |
| 177 |
|
| 178 |
namespace cwg114 { // cwg114: 2.7 |
| 179 |
struct A { |
| 180 |
virtual void f(int) = 0; // #cwg114-A-f |
| 181 |
}; |
| 182 |
struct B : A { |
| 183 |
template<typename T> void f(T); |
| 184 |
void g() { f(0); } |
| 185 |
} b; |
| 186 |
// expected-error@-1 {{variable type 'struct B' is an abstract class}} |
| 187 |
// expected-note@#cwg114-A-f {{unimplemented pure virtual method 'f' in 'B'}} |
| 188 |
} // namespace cwg114 |
| 189 |
|
| 190 |
namespace cwg115 { // cwg115: 3.0 |
| 191 |
template<typename T> int f(T); // #cwg115-f |
| 192 |
template<typename T> int g(T); // #cwg115-g |
| 193 |
template<typename T> int g(T, int); // #cwg115-g-int |
| 194 |
|
| 195 |
int k1 = f(&f); |
| 196 |
// expected-error@-1 {{no matching function for call to 'f'}} |
| 197 |
// expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}} |
| 198 |
int k2 = f(&f<int>); |
| 199 |
int k3 = f(&g<int>); |
| 200 |
// expected-error@-1 {{no matching function for call to 'f'}} |
| 201 |
// expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}} |
| 202 |
|
| 203 |
void h() { |
| 204 |
(void)&f; |
| 205 |
// expected-error@-1 {{address of overloaded function 'f' cannot be cast to type 'void'}} |
| 206 |
// expected-note@#cwg115-f {{candidate function template}} |
| 207 |
(void)&f<int>; |
| 208 |
(void)&g<int>; |
| 209 |
// expected-error@-1 {{address of overloaded function 'g' cannot be cast to type 'void'}} |
| 210 |
// expected-note@#cwg115-g-int {{candidate function template}} |
| 211 |
// expected-note@#cwg115-g {{candidate function template}} |
| 212 |
|
| 213 |
&f; |
| 214 |
// expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}} |
| 215 |
// expected-note@#cwg115-f {{possible target for call}} |
| 216 |
&f<int>; |
| 217 |
// expected-warning@-1 {{expression result unused}} |
| 218 |
&g<int>; |
| 219 |
// expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}} |
| 220 |
// expected-note@#cwg115-g-int {{possible target for call}} |
| 221 |
// expected-note@#cwg115-g {{possible target for call}} |
| 222 |
} |
| 223 |
|
| 224 |
struct S { |
| 225 |
template<typename T> static int f(T); |
| 226 |
template<typename T> static int g(T); |
| 227 |
template<typename T> static int g(T, int); |
| 228 |
} s; |
| 229 |
|
| 230 |
int k4 = f(&s.f); |
| 231 |
// expected-error@-1 {{cannot create a non-constant pointer to member function}} |
| 232 |
int k5 = f(&s.f<int>); |
| 233 |
int k6 = f(&s.g<int>); |
| 234 |
// expected-error@-1 {{cannot create a non-constant pointer to member function}} |
| 235 |
|
| 236 |
void i() { |
| 237 |
(void)&s.f; |
| 238 |
// expected-error@-1 {{cannot create a non-constant pointer to member function}} |
| 239 |
(void)&s.f<int>; |
| 240 |
(void)&s.g<int>; |
| 241 |
// expected-error@-1 {{cannot create a non-constant pointer to member function}} |
| 242 |
|
| 243 |
&s.f; |
| 244 |
// expected-error@-1 {{cannot create a non-constant pointer to member function}} |
| 245 |
&s.f<int>; |
| 246 |
// expected-warning@-1 {{expression result unused}} |
| 247 |
&s.g<int>; |
| 248 |
// expected-error@-1 {{cannot create a non-constant pointer to member function}} |
| 249 |
} |
| 250 |
|
| 251 |
struct T { |
| 252 |
template<typename T> int f(T); |
| 253 |
template<typename T> int g(T); |
| 254 |
template<typename T> int g(T, int); |
| 255 |
} t; |
| 256 |
|
| 257 |
int k7 = f(&s.f); |
| 258 |
// expected-error@-1 {{cannot create a non-constant pointer to member function}} |
| 259 |
int k8 = f(&s.f<int>); |
| 260 |
int k9 = f(&s.g<int>); |
| 261 |
// expected-error@-1 {{cannot create a non-constant pointer to member function}} |
| 262 |
|
| 263 |
void j() { |
| 264 |
(void)&s.f; |
| 265 |
// expected-error@-1 {{cannot create a non-constant pointer to member function}} |
| 266 |
(void)&s.f<int>; |
| 267 |
(void)&s.g<int>; |
| 268 |
// expected-error@-1 {{cannot create a non-constant pointer to member function}} |
| 269 |
|
| 270 |
&s.f; |
| 271 |
// expected-error@-1 {{cannot create a non-constant pointer to member function}} |
| 272 |
&s.f<int>; |
| 273 |
// expected-warning@-1 {{expression result unused}} |
| 274 |
&s.g<int>; |
| 275 |
// expected-error@-1 {{cannot create a non-constant pointer to member function}} |
| 276 |
} |
| 277 |
|
| 278 |
#if __cplusplus >= 201103L |
| 279 |
// Special case kicks in only if a template argument list is specified. |
| 280 |
template<typename T=int> void with_default(); // #cwg115-with-default |
| 281 |
int k10 = f(&with_default); |
| 282 |
// since-cxx11-error@-1 {{no matching function for call to 'f'}} |
| 283 |
// since-cxx11-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}} |
| 284 |
int k11 = f(&with_default<>); |
| 285 |
void k() { |
| 286 |
(void)&with_default; |
| 287 |
// since-cxx11-error@-1 {{address of overloaded function 'with_default' cannot be cast to type 'void'}} |
| 288 |
// since-cxx11-note@#cwg115-with-default {{candidate function template}} |
| 289 |
(void)&with_default<>; |
| 290 |
&with_default; |
| 291 |
// since-cxx11-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}} |
| 292 |
// since-cxx11-note@#cwg115-with-default {{possible target for call}} |
| 293 |
&with_default<>; |
| 294 |
// since-cxx11-warning@-1 {{expression result unused}} |
| 295 |
} |
| 296 |
#endif |
| 297 |
} // namespace cwg115 |
| 298 |
|
| 299 |
namespace cwg116 { // cwg116: 2.7 |
| 300 |
template<int> struct A {}; |
| 301 |
template<int N> void f(A<N>) {} // #cwg116-f-N |
| 302 |
template<int M> void f(A<M>) {} |
| 303 |
// expected-error@-1 {{redefinition of 'f'}} |
| 304 |
// expected-note@#cwg116-f-N {{previous definition is here}} |
| 305 |
template<typename T> void f(A<sizeof(T)>) {} // #cwg116-f-T |
| 306 |
template<typename U> void f(A<sizeof(U)>) {} |
| 307 |
// expected-error@-1 {{redefinition of 'f'}} |
| 308 |
// expected-note@#cwg116-f-T {{previous definition is here}} |
| 309 |
} // namespace cwg116 |
| 310 |
|
| 311 |
// cwg117: na |
| 312 |
// cwg118 is in cwg118.cpp |
| 313 |
// cwg119: na |
| 314 |
// cwg120: na |
| 315 |
|
| 316 |
namespace cwg121 { // cwg121: 2.7 |
| 317 |
struct X { |
| 318 |
template<typename T> struct Y {}; |
| 319 |
}; |
| 320 |
template<typename T> struct Z { |
| 321 |
X::Y<T> x; |
| 322 |
T::Y<T> y; |
| 323 |
// expected-error@-1 {{use 'template' keyword to treat 'Y' as a dependent template name}} |
| 324 |
// cxx98-17-error@-2 {{missing 'typename' prior to dependent type name 'T::Y' is a C++20 extension}} |
| 325 |
}; |
| 326 |
Z<X> z; |
| 327 |
} // namespace cwg121 |
| 328 |
|
| 329 |
namespace cwg122 { // cwg122: 2.7 |
| 330 |
template<typename T> void f(); |
| 331 |
void g() { f<int>(); } |
| 332 |
} // namespace cwg122 |
| 333 |
|
| 334 |
// cwg123: na |
| 335 |
// cwg124 is in cwg124.cpp |
| 336 |
|
| 337 |
// cwg125: 2.7 |
| 338 |
struct cwg125_A { struct cwg125_B {}; }; // #cwg125_B |
| 339 |
cwg125_A::cwg125_B cwg125_C(); |
| 340 |
namespace cwg125_B { cwg125_A cwg125_C(); } |
| 341 |
namespace cwg125 { |
| 342 |
struct X { |
| 343 |
friend cwg125_A::cwg125_B (::cwg125_C)(); // ok |
| 344 |
friend cwg125_A (::cwg125_B::cwg125_C)(); // ok |
| 345 |
friend cwg125_A::cwg125_B::cwg125_C(); // #cwg125_C |
| 346 |
// expected-error@#cwg125_C {{missing return type for function 'cwg125_C'; did you mean the constructor name 'cwg125_B'?}} |
| 347 |
// cxx98-error@#cwg125_C {{'cwg125_B' is missing exception specification 'throw()'}} |
| 348 |
// cxx98-note@#cwg125_B {{previous declaration is here}} |
| 349 |
// since-cxx11-error@#cwg125_C {{'cwg125_B' is missing exception specification 'noexcept'}} |
| 350 |
// since-cxx11-note@#cwg125_B {{previous declaration is here}} |
| 351 |
}; |
| 352 |
} // namespace cwg125 |
| 353 |
|
| 354 |
namespace cwg126 { // cwg126: partial |
| 355 |
// FIXME: We do not yet generate correct code for this change: |
| 356 |
// eg: |
| 357 |
// catch (void*&) should catch void* but not int* |
| 358 |
// catch (void*) and catch (void*const&) should catch both |
| 359 |
// Likewise: |
| 360 |
// catch (Base *&) should catch Base* but not Derived* |
| 361 |
// catch (Base *) should catch both |
| 362 |
// In each case, we emit the same code for both catches. |
| 363 |
// |
| 364 |
// The ABI does not let us represent the language rule in the unwind tables. |
| 365 |
// So, when catching by non-const (or volatile) reference to pointer, we |
| 366 |
// should compare the exception type to the caught type and only accept an |
| 367 |
// exact match. |
| 368 |
struct C {}; |
| 369 |
struct D : C {}; |
| 370 |
struct E : private C { friend class A; friend class B; }; |
| 371 |
struct F : protected C {}; |
| 372 |
struct G : C {}; |
| 373 |
struct H : D, G {}; |
| 374 |
|
| 375 |
#if __cplusplus <= 201402L |
| 376 |
struct A { |
| 377 |
virtual void cp() throw(C*); |
| 378 |
virtual void dp() throw(C*); |
| 379 |
virtual void ep() throw(C*); // #cwg126-ep |
| 380 |
virtual void fp() throw(C*); // #cwg126-fp |
| 381 |
virtual void gp() throw(C*); |
| 382 |
virtual void hp() throw(C*); // #cwg126-hp |
| 383 |
|
| 384 |
virtual void cr() throw(C&); |
| 385 |
virtual void dr() throw(C&); |
| 386 |
virtual void er() throw(C&); // #cwg126-er |
| 387 |
virtual void fr() throw(C&); // #cwg126-fr |
| 388 |
virtual void gr() throw(C&); |
| 389 |
virtual void hr() throw(C&); // #cwg126-hr |
| 390 |
|
| 391 |
virtual void pv() throw(void*); |
| 392 |
|
| 393 |
virtual void np() throw(C*); |
| 394 |
virtual void npm() throw(int C::*); |
| 395 |
virtual void nr() throw(C*&); // #cwg126-nr |
| 396 |
virtual void ncr() throw(C*const&); |
| 397 |
|
| 398 |
virtual void ref1() throw(C *const&); |
| 399 |
virtual void ref2() throw(C *); |
| 400 |
|
| 401 |
virtual void v() throw(int); |
| 402 |
virtual void w() throw(const int); |
| 403 |
virtual void x() throw(int*); // #cwg126-x |
| 404 |
virtual void y() throw(const int*); |
| 405 |
virtual void z() throw(int); // #cwg126-z |
| 406 |
}; |
| 407 |
struct B : A { |
| 408 |
virtual void cp() throw(C*); |
| 409 |
virtual void dp() throw(D*); |
| 410 |
virtual void ep() throw(E*); |
| 411 |
// cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} |
| 412 |
// cxx98-14-note@#cwg126-ep {{overridden virtual function is here}} |
| 413 |
virtual void fp() throw(F*); |
| 414 |
// cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} |
| 415 |
// cxx98-14-note@#cwg126-fp {{overridden virtual function is here}} |
| 416 |
virtual void gp() throw(G*); |
| 417 |
virtual void hp() throw(H*); |
| 418 |
// cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} |
| 419 |
// cxx98-14-note@#cwg126-hp {{overridden virtual function is here}} |
| 420 |
|
| 421 |
virtual void cr() throw(C&); |
| 422 |
virtual void dr() throw(D&); |
| 423 |
virtual void er() throw(E&); |
| 424 |
// cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} |
| 425 |
// cxx98-14-note@#cwg126-er {{overridden virtual function is here}} |
| 426 |
virtual void fr() throw(F&); |
| 427 |
// cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} |
| 428 |
// cxx98-14-note@#cwg126-fr {{overridden virtual function is here}} |
| 429 |
virtual void gr() throw(G&); |
| 430 |
virtual void hr() throw(H&); |
| 431 |
// cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} |
| 432 |
// cxx98-14-note@#cwg126-hr {{overridden virtual function is here}} |
| 433 |
|
| 434 |
virtual void pv() throw(C*); |
| 435 |
|
| 436 |
#if __cplusplus >= 201103L |
| 437 |
using nullptr_t = decltype(nullptr); |
| 438 |
virtual void np() throw(nullptr_t); |
| 439 |
virtual void npm() throw(nullptr_t&); |
| 440 |
virtual void nr() throw(nullptr_t); |
| 441 |
// cxx11-14-error@-1 {{exception specification of overriding function is more lax than base version}} |
| 442 |
// cxx11-14-note@#cwg126-nr {{overridden virtual function is here}} |
| 443 |
virtual void ncr() throw(nullptr_t); |
| 444 |
#endif // __cplusplus >= 201103L |
| 445 |
|
| 446 |
virtual void ref1() throw(D *const &); |
| 447 |
virtual void ref2() throw(D *); |
| 448 |
|
| 449 |
virtual void v() throw(const int); |
| 450 |
virtual void w() throw(int); |
| 451 |
virtual void x() throw(const int*); |
| 452 |
// cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} |
| 453 |
// cxx98-14-note@#cwg126-x {{overridden virtual function is here}} |
| 454 |
virtual void y() throw(int*); // ok |
| 455 |
virtual void z() throw(long); |
| 456 |
// cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} |
| 457 |
// cxx98-14-note@#cwg126-z {{overridden virtual function is here}} |
| 458 |
}; |
| 459 |
#endif // __cplusplus <= 201402L |
| 460 |
void f() throw(int); |
| 461 |
// since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}} |
| 462 |
// since-cxx17-note@-2 {{use 'noexcept(false)' instead}} |
| 463 |
} // namespace cwg126 |
| 464 |
|
| 465 |
namespace cwg127 { // cwg127: 2.9 |
| 466 |
__extension__ typedef __decltype(sizeof(0)) size_t; |
| 467 |
template<typename T> struct A { |
| 468 |
A() { throw 0; } |
| 469 |
void *operator new(size_t, const char * = 0); |
| 470 |
void operator delete(void *, const char *) { T::error; } // #cwg127-delete-const-char |
| 471 |
// expected-error@#cwg127-delete-const-char {{type 'void' cannot be used prior to '::' because it has no members}} |
| 472 |
// expected-note@#cwg127-p {{in instantiation of member function 'cwg127::A<void>::operator delete' requested here}} |
| 473 |
// expected-error@#cwg127-delete-const-char {{type 'int' cannot be used prior to '::' because it has no members}} |
| 474 |
// expected-note@#cwg127-q {{in instantiation of member function 'cwg127::A<int>::operator delete' requested here}} |
| 475 |
void operator delete(void *) { T::error; } |
| 476 |
}; |
| 477 |
A<void> *p = new A<void>; // #cwg127-p |
| 478 |
A<int> *q = new ("") A<int>; // #cwg127-q |
| 479 |
} // namespace cwg127 |
| 480 |
|
| 481 |
namespace cwg128 { // cwg128: 2.7 |
| 482 |
enum E1 { e1 } x = e1; |
| 483 |
enum E2 { e2 } y = static_cast<E2>(x), z = static_cast<E2>(e1); |
| 484 |
} // namespace cwg128 |
| 485 |
|
| 486 |
// cwg129: dup 616 |
| 487 |
// cwg130: na |
| 488 |
|
| 489 |
namespace cwg131 { // cwg131: sup P1949 |
| 490 |
const char *a_with_\u0e8c = "\u0e8c"; |
| 491 |
const char *b_with_\u0e8d = "\u0e8d"; |
| 492 |
const char *c_with_\u0e8e = "\u0e8e"; |
| 493 |
} // namespace cwg131 |
| 494 |
|
| 495 |
namespace cwg132 { // cwg132: no |
| 496 |
void f() { |
| 497 |
extern struct {} x; // ok |
| 498 |
extern struct S {} y; // FIXME: This is invalid. |
| 499 |
} |
| 500 |
static enum { E } e; |
| 501 |
} // namespace cwg132 |
| 502 |
|
| 503 |
// cwg133: dup 87 |
| 504 |
// cwg134: na |
| 505 |
|
| 506 |
namespace cwg135 { // cwg135: 2.7 |
| 507 |
struct A { |
| 508 |
A f(A a) { return a; } |
| 509 |
friend A g(A a) { return a; } |
| 510 |
static A h(A a) { return a; } |
| 511 |
}; |
| 512 |
} // namespace cwg135 |
| 513 |
|
| 514 |
namespace cwg136 { // cwg136: 3.4 |
| 515 |
void f(int, int, int = 0); // #cwg136-f |
| 516 |
void g(int, int, int); // #cwg136-g |
| 517 |
struct A { |
| 518 |
friend void f(int, int = 0, int); |
| 519 |
// expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} |
| 520 |
// expected-note@#cwg136-f {{previous declaration is here}} |
| 521 |
friend void g(int, int, int = 0); |
| 522 |
// expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} |
| 523 |
// expected-note@#cwg136-g {{previous declaration is here}} |
| 524 |
friend void h(int, int, int = 0); |
| 525 |
// expected-error@-1 {{friend declaration specifying a default argument must be a definition}} |
| 526 |
friend void i(int, int, int = 0) {} // #cwg136-A-i |
| 527 |
friend void j(int, int, int = 0) {} |
| 528 |
operator int(); |
| 529 |
}; |
| 530 |
void i(int, int, int); |
| 531 |
// expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} |
| 532 |
// expected-note@#cwg136-A-i {{previous declaration is here}} |
| 533 |
void q() { |
| 534 |
j(A(), A()); // ok, has default argument |
| 535 |
} |
| 536 |
extern "C" void k(int, int, int, int); // #cwg136-k |
| 537 |
namespace NSA { |
| 538 |
struct A { |
| 539 |
friend void cwg136::k(int, int, int, int = 0); |
| 540 |
// expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} |
| 541 |
// expected-note@#cwg136-k {{previous declaration is here}} |
| 542 |
}; |
| 543 |
} |
| 544 |
namespace NSB { |
| 545 |
struct A { |
| 546 |
friend void cwg136::k(int, int, int = 0, int); // #cwg136-friend-k |
| 547 |
// expected-error@#cwg136-friend-k {{friend declaration specifying a default argument must be the only declaration}} |
| 548 |
// expected-note@#cwg136-k {{previous declaration is here}} |
| 549 |
// expected-error@#cwg136-friend-k {{missing default argument on parameter}} |
| 550 |
}; |
| 551 |
} |
| 552 |
struct B { |
| 553 |
void f(int); // #cwg136-B-f |
| 554 |
}; |
| 555 |
struct C { |
| 556 |
friend void B::f(int = 0); |
| 557 |
// expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} |
| 558 |
// expected-note@#cwg136-B-f {{previous declaration is here}} |
| 559 |
}; |
| 560 |
} // namespace cwg136 |
| 561 |
|
| 562 |
namespace cwg137 { // cwg137: 2.7 |
| 563 |
extern void *p; |
| 564 |
extern const void *cp; |
| 565 |
extern volatile void *vp; |
| 566 |
extern const volatile void *cvp; |
| 567 |
int *q = static_cast<int*>(p); |
| 568 |
int *qc = static_cast<int*>(cp); |
| 569 |
// expected-error@-1 {{static_cast from 'const void *' to 'int *' casts away qualifiers}} |
| 570 |
int *qv = static_cast<int*>(vp); |
| 571 |
// expected-error@-1 {{static_cast from 'volatile void *' to 'int *' casts away qualifiers}} |
| 572 |
int *qcv = static_cast<int*>(cvp); |
| 573 |
// expected-error@-1 {{static_cast from 'const volatile void *' to 'int *' casts away qualifiers}} |
| 574 |
const int *cq = static_cast<const int*>(p); |
| 575 |
const int *cqc = static_cast<const int*>(cp); |
| 576 |
const int *cqv = static_cast<const int*>(vp); |
| 577 |
// expected-error@-1 {{static_cast from 'volatile void *' to 'const int *' casts away qualifiers}} |
| 578 |
const int *cqcv = static_cast<const int*>(cvp); |
| 579 |
// expected-error@-1 {{static_cast from 'const volatile void *' to 'const int *' casts away qualifiers}} |
| 580 |
const volatile int *cvq = static_cast<const volatile int*>(p); |
| 581 |
const volatile int *cvqc = static_cast<const volatile int*>(cp); |
| 582 |
const volatile int *cvqv = static_cast<const volatile int*>(vp); |
| 583 |
const volatile int *cvqcv = static_cast<const volatile int*>(cvp); |
| 584 |
} // namespace cwg137 |
| 585 |
|
| 586 |
namespace cwg138 { // cwg138: partial |
| 587 |
namespace example1 { |
| 588 |
void foo(); // #cwg138-ex1-foo |
| 589 |
namespace A { |
| 590 |
using example1::foo; // #cwg138-ex1-using |
| 591 |
class X { |
| 592 |
static const int i = 10; |
| 593 |
// This friend declaration is using neither qualified-id nor template-id, |
| 594 |
// so name 'foo' is not looked up, which means the using-declaration has no effect. |
| 595 |
// Target scope of this declaration is A, so this is grating friendship to |
| 596 |
// (hypothetical) A::foo instead of 'example1::foo' using declaration refers to. |
| 597 |
// A::foo corresponds to example1::foo named by the using declaration, |
| 598 |
// and since A::foo is a different entity, they potentially conflict. |
| 599 |
// FIXME: This is ill-formed, but not for the reason diagnostic says. |
| 600 |
friend void foo(); |
| 601 |
// expected-error@-1 {{cannot befriend target of using declaration}} |
| 602 |
// expected-note@#cwg138-ex1-foo {{target of using declaration}} |
| 603 |
// expected-note@#cwg138-ex1-using {{using declaration}} |
| 604 |
}; |
| 605 |
} |
| 606 |
} // namespace example1 |
| 607 |
|
| 608 |
namespace example2 { |
| 609 |
void f(); |
| 610 |
void g(); |
| 611 |
class B { |
| 612 |
void g(); |
| 613 |
}; |
| 614 |
class A : public B { |
| 615 |
static const int i = 10; |
| 616 |
void f(); |
| 617 |
// Both friend declaration are not using qualified-ids or template-ids, |
| 618 |
// so 'f' and 'g' are not looked up, which means that presence of A::f |
| 619 |
// and base B have no effect. |
| 620 |
// Both target scope of namespace 'example2', and grant friendship to |
| 621 |
// example2::f and example2::g respectively. |
| 622 |
friend void f(); |
| 623 |
friend void g(); |
| 624 |
}; |
| 625 |
void f() { |
| 626 |
int i2 = A::i; |
| 627 |
} |
| 628 |
void g() { |
| 629 |
int i3 = A::i; |
| 630 |
} |
| 631 |
} // namespace example2 |
| 632 |
|
| 633 |
namespace example3 { |
| 634 |
struct Base { |
| 635 |
private: |
| 636 |
static const int i = 10; // #cwg138-ex3-Base-i |
| 637 |
|
| 638 |
public: |
| 639 |
struct Data; |
| 640 |
// Elaborated type specifier is not the sole constituent of declaration, |
| 641 |
// so 'Data' undergoes unqualified type-only lookup, which finds Base::Data. |
| 642 |
friend class Data; |
| 643 |
|
| 644 |
struct Data { |
| 645 |
void f() { |
| 646 |
int i2 = Base::i; |
| 647 |
} |
| 648 |
}; |
| 649 |
}; |
| 650 |
struct Data { |
| 651 |
void f() { |
| 652 |
int i2 = Base::i; |
| 653 |
// expected-error@-1 {{'i' is a private member of 'cwg138::example3::Base'}} |
| 654 |
// expected-note@#cwg138-ex3-Base-i {{declared private here}} |
| 655 |
} |
| 656 |
}; |
| 657 |
} // namespace example3 |
| 658 |
} // namespace cwg138 |
| 659 |
|
| 660 |
namespace cwg139 { // cwg139: 2.7 |
| 661 |
namespace example1 { |
| 662 |
typedef int f; // #cwg139-typedef-f |
| 663 |
struct A { |
| 664 |
friend void f(A &); |
| 665 |
// expected-error@-1 {{redefinition of 'f' as different kind of symbol}} |
| 666 |
// expected-note@#cwg139-typedef-f {{previous definition is here}} |
| 667 |
}; |
| 668 |
} |
| 669 |
|
| 670 |
namespace example2 { |
| 671 |
typedef int f; |
| 672 |
namespace N { |
| 673 |
struct A { |
| 674 |
friend void f(A &); |
| 675 |
operator int(); |
| 676 |
void g(A a) { int i = f(a); } // ok, f is typedef not friend function |
| 677 |
}; |
| 678 |
} |
| 679 |
} |
| 680 |
} // namespace cwg139 |
| 681 |
|
| 682 |
namespace cwg140 { // cwg140: 2.7 |
| 683 |
void f(int *const) {} // #cwg140-f-first |
| 684 |
void f(int[3]) {} |
| 685 |
// expected-error@-1 {{redefinition of 'f'}} |
| 686 |
// expected-note@#cwg140-f-first {{previous definition is here}} |
| 687 |
void g(const int); |
| 688 |
void g(int n) { n = 2; } |
| 689 |
} // namespace cwg140 |
| 690 |
|
| 691 |
namespace cwg141 { // cwg141: 3.1 |
| 692 |
template<typename T> void f(); |
| 693 |
template<typename T> struct S { int n; }; // #cwg141-S |
| 694 |
struct A : S<int> { |
| 695 |
template<typename T> void f(); |
| 696 |
template<typename T> struct S {}; // #cwg141-A-S |
| 697 |
} a; |
| 698 |
struct B : S<int> {} b; |
| 699 |
void g() { |
| 700 |
a.f<int>(); |
| 701 |
(void)a.S<int>::n; // #cwg141-a |
| 702 |
// cxx98-error@#cwg141-a {{lookup of 'S' in member access expression is ambiguous; using member of 'struct A'}} |
| 703 |
// cxx98-note@#cwg141-A-S {{lookup in the object type 'struct A' refers here}} |
| 704 |
// cxx98-note@#cwg141-S {{lookup from the current scope refers here}} |
| 705 |
// expected-error@#cwg141-a {{no member named 'n' in 'cwg141::A::S<int>'}} |
| 706 |
// FIXME: we issue a useful diagnostic first, then some bogus ones. |
| 707 |
b.f<int>(); |
| 708 |
// expected-error@-1 {{no member named 'f' in 'cwg141::B'}} |
| 709 |
// expected-error@-2 +{{}} |
| 710 |
(void)b.S<int>::n; |
| 711 |
} |
| 712 |
template<typename T> struct C { |
| 713 |
T t; |
| 714 |
void g() { |
| 715 |
t.f<int>(); |
| 716 |
// expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}} |
| 717 |
} |
| 718 |
void h() { |
| 719 |
(void)t.S<int>::n; // ok |
| 720 |
} |
| 721 |
void i() { |
| 722 |
(void)t.S<int>(); // ok! |
| 723 |
} |
| 724 |
}; |
| 725 |
void h() { C<B>().h(); } // ok |
| 726 |
struct X { |
| 727 |
template<typename T> void S(); |
| 728 |
}; |
| 729 |
void i() { C<X>().i(); } // ok!! |
| 730 |
} // namespace cwg141 |
| 731 |
|
| 732 |
namespace cwg142 { // cwg142: 2.8 |
| 733 |
class B { // #cwg142-B |
| 734 |
public: |
| 735 |
int mi; // #cwg142-B-mi |
| 736 |
static int si; // #cwg142-B-si |
| 737 |
}; |
| 738 |
class D : private B { // #cwg142-D |
| 739 |
}; |
| 740 |
class DD : public D { |
| 741 |
void f(); |
| 742 |
}; |
| 743 |
void DD::f() { |
| 744 |
mi = 3; |
| 745 |
// expected-error@-1 {{'mi' is a private member of 'cwg142::B'}} |
| 746 |
// expected-note@#cwg142-D {{constrained by private inheritance here}} |
| 747 |
// expected-note@#cwg142-B-mi {{member is declared here}} |
| 748 |
si = 3; |
| 749 |
// expected-error@-1 {{'si' is a private member of 'cwg142::B'}} |
| 750 |
// expected-note@#cwg142-D {{constrained by private inheritance here}} |
| 751 |
// expected-note@#cwg142-B-si {{member is declared here}} |
| 752 |
B b_old; |
| 753 |
// expected-error@-1 {{'B' is a private member of 'cwg142::B'}} |
| 754 |
// expected-note@#cwg142-D {{constrained by private inheritance here}} |
| 755 |
// expected-note@#cwg142-B {{member is declared here}} |
| 756 |
cwg142::B b; |
| 757 |
b.mi = 3; |
| 758 |
b.si = 3; |
| 759 |
B::si = 3; |
| 760 |
// expected-error@-1 {{'B' is a private member of 'cwg142::B'}} |
| 761 |
// expected-note@#cwg142-D {{constrained by private inheritance here}} |
| 762 |
// expected-note@#cwg142-B {{member is declared here}} |
| 763 |
cwg142::B::si = 3; |
| 764 |
B *bp1_old = this; // #cwg142-bp1_old |
| 765 |
// expected-error@#cwg142-bp1_old {{'B' is a private member of 'cwg142::B'}} |
| 766 |
// expected-note@#cwg142-D {{constrained by private inheritance here}} |
| 767 |
// expected-note@#cwg142-B {{member is declared here}} |
| 768 |
// expected-error@#cwg142-bp1_old {{cannot cast 'cwg142::DD' to its private base class 'B'}} |
| 769 |
// expected-note@#cwg142-D {{declared private here}} |
| 770 |
cwg142::B *bp1 = this; |
| 771 |
// expected-error@-1 {{cannot cast 'cwg142::DD' to its private base class 'cwg142::B'}} |
| 772 |
// expected-note@#cwg142-D {{declared private here}} |
| 773 |
B *bp2_old = (B*)this; // #cwg142-bp2_old |
| 774 |
// expected-error@#cwg142-bp2_old {{'B' is a private member of 'cwg142::B'}} |
| 775 |
// expected-note@#cwg142-D {{constrained by private inheritance here}} |
| 776 |
// expected-note@#cwg142-B {{member is declared here}} |
| 777 |
// expected-error@#cwg142-bp2_old {{'B' is a private member of 'cwg142::B'}} |
| 778 |
// expected-note@#cwg142-D {{constrained by private inheritance here}} |
| 779 |
// expected-note@#cwg142-B {{member is declared here}} |
| 780 |
cwg142::B *bp2 = (cwg142::B*)this; |
| 781 |
bp2->mi = 3; |
| 782 |
} |
| 783 |
} // namespace cwg142 |
| 784 |
|
| 785 |
namespace cwg143 { // cwg143: 2.7 |
| 786 |
namespace A { struct X; } |
| 787 |
namespace B { void f(A::X); } |
| 788 |
namespace A { |
| 789 |
struct X { friend void B::f(X); }; |
| 790 |
} |
| 791 |
void g(A::X x) { |
| 792 |
f(x); |
| 793 |
// expected-error@-1 {{use of undeclared identifier 'f'}} |
| 794 |
} |
| 795 |
} // namespace cwg143 |
| 796 |
|
| 797 |
namespace cwg145 { // cwg145: 2.7 |
| 798 |
void f(bool b) { |
| 799 |
++b; |
| 800 |
// cxx98-14-warning@-1 {{incrementing expression of type bool is deprecated and incompatible with C++17}} |
| 801 |
// since-cxx17-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}} |
| 802 |
b++; |
| 803 |
// cxx98-14-warning@-1 {{incrementing expression of type bool is deprecated and incompatible with C++17}} |
| 804 |
// since-cxx17-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}} |
| 805 |
} |
| 806 |
} // namespace cwg145 |
| 807 |
|
| 808 |
namespace cwg147 { // cwg147: 2.7 |
| 809 |
namespace example1 { |
| 810 |
template<typename> struct A { |
| 811 |
template<typename T> A(T); |
| 812 |
}; |
| 813 |
// Per core issue 1435, this is ill-formed because A<int>::A<int> does not |
| 814 |
// name the injected-class-name. (A<int>::A does, though.) |
| 815 |
template<> template<> A<int>::A<int>(int) {} |
| 816 |
// expected-error@-1 {{out-of-line constructor for 'A' cannot have template arguments}} |
| 817 |
template<> template<> A<float>::A(float) {} |
| 818 |
} |
| 819 |
namespace example2 { |
| 820 |
struct A { A(); }; |
| 821 |
struct B : A { B(); }; |
| 822 |
A::A a1; |
| 823 |
// expected-error@-1 {{qualified reference to 'A' is a constructor name rather than a type in this context}} |
| 824 |
B::A a2; |
| 825 |
} |
| 826 |
namespace example3 { |
| 827 |
template<typename> struct A { |
| 828 |
template<typename T> A(T); |
| 829 |
static A a; |
| 830 |
}; |
| 831 |
template<> A<int>::A<int>(A<int>::a); |
| 832 |
// expected-error@-1 {{qualified reference to 'A' is a constructor name rather than a template name in this context}} |
| 833 |
} |
| 834 |
} // namespace cwg147 |
| 835 |
|
| 836 |
namespace cwg148 { // cwg148: 2.7 |
| 837 |
struct A { int A::*p; }; |
| 838 |
static_assert(__is_pod(int(A::*)), ""); |
| 839 |
static_assert(__is_pod(A), ""); |
| 840 |
} // namespace cwg148 |
| 841 |
|
| 842 |
// cwg149: na |
| 843 |
|
| 844 |
namespace cwg150 { // cwg150: 19 |
| 845 |
namespace p1 { |
| 846 |
template <class T, class U = int> |
| 847 |
class ARG { }; |
| 848 |
|
| 849 |
template <class X, template <class Y> class PARM> |
| 850 |
void f(PARM<X>) { } |
| 851 |
|
| 852 |
void g() { |
| 853 |
ARG<int> x; |
| 854 |
f(x); |
| 855 |
} |
| 856 |
} // namespace p1 |
| 857 |
|
| 858 |
namespace p2 { |
| 859 |
template <template <class T, class U = int> class PARM> |
| 860 |
class C { |
| 861 |
PARM<int> pi; |
| 862 |
}; |
| 863 |
} // namespace p2 |
| 864 |
|
| 865 |
namespace n1 { |
| 866 |
struct Dense { static const unsigned int dim = 1; }; |
| 867 |
|
| 868 |
template <template <typename> class View, |
| 869 |
typename Block> |
| 870 |
void operator+(float, View<Block> const&); |
| 871 |
|
| 872 |
template <typename Block, |
| 873 |
unsigned int Dim = Block::dim> |
| 874 |
class Lvalue_proxy { operator float() const; }; |
| 875 |
|
| 876 |
void test_1d (void) { |
| 877 |
Lvalue_proxy<Dense> p; |
| 878 |
float b; |
| 879 |
b + p; |
| 880 |
} |
| 881 |
} // namespace n1 |
| 882 |
} // namespace cwg150 |
| 883 |
|
| 884 |
namespace cwg151 { // cwg151: 3.1 |
| 885 |
struct X {}; |
| 886 |
typedef int X::*p; |
| 887 |
static_assert(__enable_constant_folding(p() == 0), ""); |
| 888 |
} // namespace cwg151 |
| 889 |
|
| 890 |
namespace cwg152 { // cwg152: 2.7 |
| 891 |
struct A { |
| 892 |
A(); // #cwg152-A-ctor |
| 893 |
explicit A(const A&); // #cwg152-A-explicit-ctor |
| 894 |
}; |
| 895 |
A a1 = A(); |
| 896 |
// cxx98-14-error@-1 {{no matching constructor for initialization of 'A'}} |
| 897 |
// cxx98-14-note@#cwg152-A-explicit-ctor {{explicit constructor is not a candidate}} |
| 898 |
// cxx98-14-note@#cwg152-A-ctor {{candidate constructor not viable: requires 0 arguments, but 1 was provided}} |
| 899 |
A a2((A())); |
| 900 |
|
| 901 |
A &f(); |
| 902 |
A a3 = f(); |
| 903 |
// expected-error@-1 {{no matching constructor for initialization of 'A'}} |
| 904 |
// expected-note@#cwg152-A-explicit-ctor {{explicit constructor is not a candidate}} |
| 905 |
// expected-note@#cwg152-A-ctor {{candidate constructor not viable: requires 0 arguments, but 1 was provided}} |
| 906 |
A a4(f()); |
| 907 |
} // namespace cwg152 |
| 908 |
|
| 909 |
// cwg153: na |
| 910 |
|
| 911 |
namespace cwg154 { // cwg154: 2.7 |
| 912 |
union { int a; }; |
| 913 |
// expected-error@-1 {{nonymous unions at namespace or global scope must be declared 'static'}} |
| 914 |
namespace { |
| 915 |
union { int b; }; |
| 916 |
} |
| 917 |
static union { int c; }; |
| 918 |
} // namespace cwg154 |
| 919 |
|
| 920 |
namespace cwg155 { // cwg155: dup 632 |
| 921 |
struct S { int n; } s = { { 1 } }; |
| 922 |
// expected-warning@-1 {{braces around scalar initializer}} |
| 923 |
} // namespace cwg155 |
| 924 |
|
| 925 |
// cwg156: sup 1111 |
| 926 |
// cwg158 is in cwg158.cpp |
| 927 |
|
| 928 |
namespace cwg159 { // cwg159: 3.5 |
| 929 |
namespace X { void f(); } |
| 930 |
void f(); |
| 931 |
void cwg159::f() {} |
| 932 |
// expected-warning@-1 {{extra qualification on member 'f'}} |
| 933 |
void cwg159::X::f() {} |
| 934 |
} // namespace cwg159 |
| 935 |
|
| 936 |
// cwg160: na |
| 937 |
|
| 938 |
namespace cwg161 { // cwg161: 3.1 |
| 939 |
class A { |
| 940 |
protected: |
| 941 |
struct B { int n; } b; // #cwg161-B |
| 942 |
static B bs; |
| 943 |
void f(); // #cwg161-f |
| 944 |
static void sf(); |
| 945 |
}; |
| 946 |
struct C : A {}; |
| 947 |
struct D : A { |
| 948 |
void g(C c) { |
| 949 |
(void)b.n; |
| 950 |
B b1; |
| 951 |
C::B b2; // ok, accessible as a member of A |
| 952 |
(void)&C::b; |
| 953 |
// expected-error@-1 {{'b' is a protected member of 'cwg161::A'}} |
| 954 |
// expected-note@#cwg161-B {{declared protected here}} |
| 955 |
(void)&C::bs; |
| 956 |
(void)c.b; |
| 957 |
// expected-error@-1 {{'b' is a protected member of 'cwg161::A'}} |
| 958 |
// expected-note@#cwg161-B {{declared protected here}} |
| 959 |
(void)c.bs; |
| 960 |
f(); |
| 961 |
sf(); |
| 962 |
c.f(); |
| 963 |
// expected-error@-1 {{protected}} |
| 964 |
// expected-note@#cwg161-f {{declared protected here}} |
| 965 |
c.sf(); |
| 966 |
A::f(); |
| 967 |
D::f(); |
| 968 |
A::sf(); |
| 969 |
C::sf(); |
| 970 |
D::sf(); |
| 971 |
} |
| 972 |
}; |
| 973 |
} // namespace cwg161 |
| 974 |
|
| 975 |
namespace cwg162 { // cwg162: 19 |
| 976 |
struct A { |
| 977 |
char &f(char); |
| 978 |
static int &f(int); |
| 979 |
|
| 980 |
void g() { |
| 981 |
int &a = (&A::f)(0); |
| 982 |
char &b = (&A::f)('0'); |
| 983 |
// expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}} |
| 984 |
} |
| 985 |
}; |
| 986 |
|
| 987 |
int &c = (&A::f)(0); |
| 988 |
char &d = (&A::f)('0'); |
| 989 |
// expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}} |
| 990 |
} // namespace cwg162 |
| 991 |
|
| 992 |
// cwg163: na |
| 993 |
|
| 994 |
namespace cwg164 { // cwg164: 2.7 |
| 995 |
void f(int); |
| 996 |
template <class T> int g(T t) { return f(t); } |
| 997 |
|
| 998 |
enum E { e }; |
| 999 |
int f(E); |
| 1000 |
|
| 1001 |
int k = g(e); |
| 1002 |
} // namespace cwg164 |
| 1003 |
|
| 1004 |
namespace cwg165 { // cwg165: no |
| 1005 |
namespace N { |
| 1006 |
struct A { friend struct B; }; |
| 1007 |
void f() { void g(); } |
| 1008 |
} |
| 1009 |
// FIXME: cwg1477 says this is ok, cwg165 says it's ill-formed |
| 1010 |
struct N::B {}; |
| 1011 |
// FIXME: cwg165 says this is ill-formed, but the argument in cwg1477 says it's ok |
| 1012 |
void N::g() {} |
| 1013 |
} // namespace cwg165 |
| 1014 |
|
| 1015 |
namespace cwg166 { // cwg166: 2.9 |
| 1016 |
namespace A { class X; } |
| 1017 |
|
| 1018 |
template<typename T> int f(T t) { return t.n; } |
| 1019 |
int g(A::X); |
| 1020 |
template<typename T> int h(T t) { return t.n; } |
| 1021 |
// expected-error@-1 {{'n' is a private member of 'cwg166::A::X'}} |
| 1022 |
// expected-note@#cwg166-h-instantiation {{in instantiation of function template specialization 'cwg166::h<cwg166::A::X>' requested here}} |
| 1023 |
// expected-note@#cwg166-X-n {{implicitly declared private here}} |
| 1024 |
int i(A::X); |
| 1025 |
|
| 1026 |
namespace A { |
| 1027 |
class X { |
| 1028 |
friend int f<X>(X); |
| 1029 |
friend int cwg166::g(X); |
| 1030 |
friend int h(X); |
| 1031 |
friend int i(X); |
| 1032 |
int n; // #cwg166-X-n |
| 1033 |
}; |
| 1034 |
|
| 1035 |
int h(X x) { return x.n; } |
| 1036 |
int i(X x) { return x.n; } |
| 1037 |
} |
| 1038 |
|
| 1039 |
template int f(A::X); |
| 1040 |
int g(A::X x) { return x.n; } |
| 1041 |
template int h(A::X); // #cwg166-h-instantiation |
| 1042 |
int i(A::X x) { return x.n; } |
| 1043 |
// expected-error@-1 {{'n' is a private member of 'cwg166::A::X'}} |
| 1044 |
// expected-note@#cwg166-X-n {{implicitly declared private here}} |
| 1045 |
} // namespace cwg166 |
| 1046 |
|
| 1047 |
// cwg167: sup 1012 |
| 1048 |
|
| 1049 |
namespace cwg168 { // cwg168: no |
| 1050 |
extern "C" typedef int (*p)(); |
| 1051 |
extern "C++" typedef int (*q)(); |
| 1052 |
struct S { |
| 1053 |
static int f(); |
| 1054 |
}; |
| 1055 |
p a = &S::f; // FIXME: this should fail. |
| 1056 |
q b = &S::f; |
| 1057 |
} // namespace cwg168 |
| 1058 |
|
| 1059 |
namespace cwg169 { // cwg169: 3.4 |
| 1060 |
template<typename> struct A { int n; }; |
| 1061 |
struct B { |
| 1062 |
template<typename> struct C; |
| 1063 |
template<typename> void f(); |
| 1064 |
template<typename> static int n; |
| 1065 |
// cxx98-11-error@-1 {{variable templates are a C++14 extension}} |
| 1066 |
}; |
| 1067 |
struct D : A<int>, B { |
| 1068 |
using A<int>::n; |
| 1069 |
using B::C<int>; |
| 1070 |
// expected-error@-1 {{using declaration cannot refer to a template specialization}} |
| 1071 |
using B::f<int>; |
| 1072 |
// expected-error@-1 {{using declaration cannot refer to a template specialization}} |
| 1073 |
using B::n<int>; |
| 1074 |
// expected-error@-1 {{using declaration cannot refer to a template specialization}} |
| 1075 |
}; |
| 1076 |
} // namespace cwg169 |
| 1077 |
|
| 1078 |
namespace cwg170 { // cwg170: 3.1 |
| 1079 |
#if __cplusplus >= 201103L |
| 1080 |
struct A {}; |
| 1081 |
struct B : A { int i; }; |
| 1082 |
struct C : A {}; |
| 1083 |
struct D : C {}; |
| 1084 |
|
| 1085 |
constexpr int f(int A::*) { return 0; } |
| 1086 |
constexpr int g(int C::*) { return 0; } |
| 1087 |
constexpr int h(int D::*) { return 0; } |
| 1088 |
|
| 1089 |
constexpr auto p = static_cast<int A::*>(&B::i); |
| 1090 |
constexpr auto q = f(p); |
| 1091 |
constexpr auto r = g(p); |
| 1092 |
// since-cxx11-error@-1 {{constexpr variable 'r' must be initialized by a constant expression}} |
| 1093 |
constexpr auto s = h(p); |
| 1094 |
// since-cxx11-error@-1 {{constexpr variable 's' must be initialized by a constant expression}} |
| 1095 |
#endif |
| 1096 |
} // namespace cwg170 |
| 1097 |
|
| 1098 |
namespace { // cwg171: 3.4 |
| 1099 |
int cwg171a; |
| 1100 |
} |
| 1101 |
int cwg171b; // #cwg171b-int |
| 1102 |
namespace cwg171 { |
| 1103 |
extern "C" void cwg171a(); |
| 1104 |
extern "C" void cwg171b(); |
| 1105 |
// expected-error@-1 {{declaration of 'cwg171b' with C language linkage conflicts with declaration in global scope}} |
| 1106 |
// expected-note@#cwg171b-int {{declared in global scope here}} |
| 1107 |
} // namespace cwg171 |
| 1108 |
|
| 1109 |
namespace cwg172 { // cwg172: 2.7 |
| 1110 |
enum { zero }; |
| 1111 |
static_assert(-1 < zero, ""); |
| 1112 |
|
| 1113 |
enum { x = -1, y = (unsigned int)-1 }; |
| 1114 |
static_assert(sizeof(x) > sizeof(int), ""); |
| 1115 |
|
| 1116 |
enum { a = (unsigned int)-1 / 2 }; |
| 1117 |
static_assert(sizeof(a) == sizeof(int), ""); |
| 1118 |
static_assert(-a < 0, ""); |
| 1119 |
|
| 1120 |
enum { b = (unsigned int)-1 / 2 + 1 }; |
| 1121 |
static_assert(sizeof(b) == sizeof(unsigned int), ""); |
| 1122 |
static_assert(-b > 0, ""); |
| 1123 |
|
| 1124 |
enum { c = (unsigned long)-1 / 2 }; |
| 1125 |
static_assert(sizeof(c) == sizeof(long), ""); |
| 1126 |
static_assert(-c < 0, ""); |
| 1127 |
|
| 1128 |
enum { d = (unsigned long)-1 / 2 + 1 }; |
| 1129 |
static_assert(sizeof(d) == sizeof(unsigned long), ""); |
| 1130 |
static_assert(-d > 0, ""); |
| 1131 |
|
| 1132 |
enum { e = (unsigned long long)-1 / 2 }; |
| 1133 |
// cxx98-error@-1 {{'long long' is a C++11 extension}} |
| 1134 |
static_assert(sizeof(e) == sizeof(long), ""); |
| 1135 |
static_assert(-e < 0, ""); |
| 1136 |
|
| 1137 |
enum { f = (unsigned long long)-1 / 2 + 1 }; |
| 1138 |
// cxx98-error@-1 {{'long long' is a C++11 extension}} |
| 1139 |
static_assert(sizeof(f) == sizeof(unsigned long), ""); |
| 1140 |
static_assert(-f > 0, ""); |
| 1141 |
} // namespace cwg172 |
| 1142 |
|
| 1143 |
namespace cwg173 { // cwg173: 2.7 |
| 1144 |
static_assert('0' + 1 == '1' && '0' + 2 == '2' && '0' + 3 == '3' && |
| 1145 |
'0' + 4 == '4' && '0' + 5 == '5' && '0' + 6 == '6' && |
| 1146 |
'0' + 7 == '7' && '0' + 8 == '8' && '0' + 9 == '9', ""); |
| 1147 |
} // namespace cwg173 |
| 1148 |
|
| 1149 |
// cwg174: sup 1012 |
| 1150 |
|
| 1151 |
namespace cwg175 { // cwg175: 2.8 |
| 1152 |
struct A {}; // #cwg175-A |
| 1153 |
struct B : private A {}; // #cwg175-B |
| 1154 |
struct C : B { |
| 1155 |
A a; |
| 1156 |
// expected-error@-1 {{'A' is a private member of 'cwg175::A'}} |
| 1157 |
// expected-note@#cwg175-B {{constrained by private inheritance here}} |
| 1158 |
// expected-note@#cwg175-A {{member is declared here}} |
| 1159 |
cwg175::A b; |
| 1160 |
}; |
| 1161 |
} // namespace cwg175 |
| 1162 |
|
| 1163 |
namespace cwg176 { // cwg176: 3.1 |
| 1164 |
template<typename T> class Y; |
| 1165 |
template<> class Y<int> { |
| 1166 |
void f() { |
| 1167 |
typedef Y A; // #cwg176-A-first |
| 1168 |
typedef Y<char> A; |
| 1169 |
// expected-error@-1 {{typedef redefinition with different types ('Y<char>' vs 'Y<int>')}} |
| 1170 |
// expected-note@#cwg176-A-first {{previous definition is here}} |
| 1171 |
} |
| 1172 |
}; |
| 1173 |
|
| 1174 |
template<typename T> struct Base {}; // #cwg176-Base |
| 1175 |
template<typename T> struct Derived : public Base<T> { |
| 1176 |
void f() { |
| 1177 |
typedef typename Derived::template Base<T> A; |
| 1178 |
typedef typename Derived::Base A; |
| 1179 |
} |
| 1180 |
}; |
| 1181 |
template struct Derived<int>; |
| 1182 |
|
| 1183 |
template<typename T> struct Derived2 : Base<int>, Base<char> { |
| 1184 |
typename Derived2::Base b; |
| 1185 |
// expected-error@-1 {{member 'Base' found in multiple base classes of different types}} |
| 1186 |
// expected-note@#cwg176-Base {{member type 'cwg176::Base<int>' found by ambiguous name lookup}} |
| 1187 |
// expected-note@#cwg176-Base {{member type 'cwg176::Base<char>' found by ambiguous name lookup}} |
| 1188 |
typename Derived2::Base<double> d; |
| 1189 |
}; |
| 1190 |
|
| 1191 |
template<typename T> class X { // #cwg176-X |
| 1192 |
X *p1; |
| 1193 |
X<T> *p2; |
| 1194 |
X<int> *p3; |
| 1195 |
cwg176::X *p4; // #cwg176-p4 |
| 1196 |
// cxx98-14-error@#cwg176-p4 {{use of class template 'cwg176::X' requires template arguments}} |
| 1197 |
// cxx98-14-note@#cwg176-X {{template is declared here}} |
| 1198 |
// since-cxx17-error@#cwg176-p4 {{use of class template 'cwg176::X' requires template arguments; argument deduction not allowed in non-static class member}} |
| 1199 |
// since-cxx17-note@#cwg176-X {{template is declared here}} |
| 1200 |
}; |
| 1201 |
} // namespace cwg176 |
| 1202 |
|
| 1203 |
namespace cwg177 { // cwg177: 2.7 |
| 1204 |
struct B {}; |
| 1205 |
struct A { |
| 1206 |
A(A &); // #cwg177-A-copy-ctor |
| 1207 |
A(const B &); // #cwg177-A-ctor-from-B |
| 1208 |
}; |
| 1209 |
B b; |
| 1210 |
A a = b; |
| 1211 |
// cxx98-14-error@-1 {{no viable constructor copying variable of type 'A'}} |
| 1212 |
// cxx98-14-note@#cwg177-A-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}} |
| 1213 |
// cxx98-14-note@#cwg177-A-ctor-from-B {{candidate constructor not viable: no known conversion from 'A' to 'const B &' for 1st argument}} |
| 1214 |
|
| 1215 |
struct C { C(C&); }; // #cwg177-C-copy-ctor |
| 1216 |
struct D : C {}; |
| 1217 |
struct E { operator D(); }; |
| 1218 |
E e; |
| 1219 |
C c = e; |
| 1220 |
// expected-error@-1 {{no viable constructor copying variable of type 'D'}} |
| 1221 |
// expected-note@#cwg177-C-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}} |
| 1222 |
} // namespace cwg177 |
| 1223 |
|
| 1224 |
namespace cwg178 { // cwg178: 3.1 |
| 1225 |
static_assert(int() == 0, ""); |
| 1226 |
#if __cplusplus >= 201103L |
| 1227 |
static_assert(int{} == 0, ""); |
| 1228 |
struct S { int a, b; }; |
| 1229 |
static_assert(S{1}.b == 0, ""); |
| 1230 |
struct T { constexpr T() : n() {} int n; }; |
| 1231 |
static_assert(T().n == 0, ""); |
| 1232 |
struct U : S { constexpr U() : S() {} }; |
| 1233 |
static_assert(U().b == 0, ""); |
| 1234 |
#endif |
| 1235 |
} // namespace cwg178 |
| 1236 |
|
| 1237 |
namespace cwg179 { // cwg179: 2.7 |
| 1238 |
void f(); |
| 1239 |
int n = &f - &f; |
| 1240 |
// expected-error@-1 {{arithmetic on pointers to the function type 'void ()'}} |
| 1241 |
} // namespace cwg179 |
| 1242 |
|
| 1243 |
namespace cwg180 { // cwg180: 2.8 |
| 1244 |
template<typename T> struct X : T, T::some_base { |
| 1245 |
X() : T::some_type_that_might_be_T(), T::some_base() {} |
| 1246 |
friend class T::some_class; |
| 1247 |
void f() { |
| 1248 |
enum T::some_enum e; |
| 1249 |
} |
| 1250 |
}; |
| 1251 |
} // namespace cwg180 |
| 1252 |
|
| 1253 |
namespace cwg181 { // cwg181: 2.7 |
| 1254 |
namespace X { |
| 1255 |
template <template X<class T> > struct A { }; |
| 1256 |
// expected-error@-1 +{{}} |
| 1257 |
template <template X<class T> > void f(A<X>) { } |
| 1258 |
// expected-error@-1 +{{}} |
| 1259 |
} |
| 1260 |
|
| 1261 |
namespace Y { |
| 1262 |
template <template <class T> class X> struct A { }; |
| 1263 |
template <template <class T> class X> void f(A<X>) { } |
| 1264 |
} |
| 1265 |
} // namespace cwg181 |
| 1266 |
|
| 1267 |
namespace cwg182 { // cwg182: 14 |
| 1268 |
template <class T> struct C { |
| 1269 |
void f(); |
| 1270 |
void g(); |
| 1271 |
}; |
| 1272 |
|
| 1273 |
template <class T> void C<T>::f() {} |
| 1274 |
template <class T> void C<T>::g() {} |
| 1275 |
|
| 1276 |
class A { |
| 1277 |
class B {}; |
| 1278 |
void f(); |
| 1279 |
}; |
| 1280 |
|
| 1281 |
template void C<A::B>::f(); |
| 1282 |
template <> void C<A::B>::g(); |
| 1283 |
|
| 1284 |
void A::f() { |
| 1285 |
C<B> cb; |
| 1286 |
cb.f(); |
| 1287 |
} |
| 1288 |
} // namespace cwg182 |
| 1289 |
|
| 1290 |
namespace cwg183 { // cwg183: sup 382 |
| 1291 |
template<typename T> struct A {}; |
| 1292 |
template<typename T> struct B { |
| 1293 |
typedef int X; |
| 1294 |
}; |
| 1295 |
template<> struct A<int> { |
| 1296 |
typename B<int>::X x; |
| 1297 |
// cxx98-error@-1 {{'typename' outside of a template is a C++11 extension}} |
| 1298 |
}; |
| 1299 |
} // namespace cwg183 |
| 1300 |
|
| 1301 |
namespace cwg184 { // cwg184: 2.7 |
| 1302 |
template<typename T = float> struct B {}; |
| 1303 |
|
| 1304 |
template<template<typename TT = float> class T> struct A { |
| 1305 |
void f(); |
| 1306 |
void g(); |
| 1307 |
}; |
| 1308 |
|
| 1309 |
template<template<typename TT> class T> void A<T>::f() { // #cwg184-T |
| 1310 |
T<> t; |
| 1311 |
// expected-error@-1 {{too few template arguments for template template parameter 'T'}} |
| 1312 |
// expected-note@#cwg184-T {{template is declared here}} |
| 1313 |
} |
| 1314 |
|
| 1315 |
template<template<typename TT = char> class T> void A<T>::g() { |
| 1316 |
T<> t; |
| 1317 |
typedef T<> X; |
| 1318 |
typedef T<char> X; |
| 1319 |
} |
| 1320 |
|
| 1321 |
void h() { A<B>().g(); } |
| 1322 |
} // namespace cwg184 |
| 1323 |
|
| 1324 |
// cwg185 is in cwg185.cpp |
| 1325 |
|
| 1326 |
namespace cwg187 { // cwg187: sup 481 |
| 1327 |
const int Z = 1; |
| 1328 |
template<int X = Z, int Z = X> struct A; |
| 1329 |
typedef A<> T; |
| 1330 |
typedef A<1, 1> T; |
| 1331 |
} // namespace cwg187 |
| 1332 |
|
| 1333 |
namespace cwg188 { // cwg188: 2.7 |
| 1334 |
char c[10]; |
| 1335 |
static_assert(sizeof(0, c) == 10, ""); |
| 1336 |
} // namespace cwg188 |
| 1337 |
|
| 1338 |
namespace cwg190 { // cwg190: 19 |
| 1339 |
struct A { |
| 1340 |
int a; |
| 1341 |
static double x; |
| 1342 |
int b; |
| 1343 |
void y(); |
| 1344 |
int c; |
| 1345 |
}; |
| 1346 |
|
| 1347 |
struct B { |
| 1348 |
int a; |
| 1349 |
void y(); |
| 1350 |
int b; |
| 1351 |
static double x; |
| 1352 |
int c; |
| 1353 |
}; |
| 1354 |
|
| 1355 |
static_assert(__is_layout_compatible(A, B), ""); |
| 1356 |
} // namespace cwg190 |
| 1357 |
|
| 1358 |
int cwg191_j; |
| 1359 |
namespace cwg191 { // cwg191: 2.7 |
| 1360 |
namespace example1 { |
| 1361 |
struct outer { |
| 1362 |
static int i; |
| 1363 |
struct inner { |
| 1364 |
void f() { |
| 1365 |
struct local { |
| 1366 |
void g() { |
| 1367 |
i = 5; |
| 1368 |
} |
| 1369 |
}; |
| 1370 |
} |
| 1371 |
}; |
| 1372 |
}; |
| 1373 |
} |
| 1374 |
|
| 1375 |
namespace example2 { |
| 1376 |
struct S { |
| 1377 |
void f() { |
| 1378 |
struct local2 { |
| 1379 |
void g() { |
| 1380 |
cwg191_j = 5; |
| 1381 |
} |
| 1382 |
}; |
| 1383 |
} |
| 1384 |
}; |
| 1385 |
} |
| 1386 |
} // namespace cwg191 |
| 1387 |
|
| 1388 |
namespace cwg192 { // cwg192: 2.7 |
| 1389 |
struct S { |
| 1390 |
void f(I i) { } |
| 1391 |
// expected-error@-1 {{unknown type name 'I'}} |
| 1392 |
typedef int I; |
| 1393 |
}; |
| 1394 |
} // namespace cwg192 |
| 1395 |
|
| 1396 |
// cwg193 is in cwg193.cpp |
| 1397 |
|
| 1398 |
namespace cwg194 { // cwg194: 2.7 |
| 1399 |
struct A { |
| 1400 |
A(); |
| 1401 |
void A(); |
| 1402 |
// expected-error@-1 {{constructor cannot have a return type}} |
| 1403 |
}; |
| 1404 |
struct B { |
| 1405 |
void B(); |
| 1406 |
// expected-error@-1 {{constructor cannot have a return type}} |
| 1407 |
B(); |
| 1408 |
}; |
| 1409 |
struct C { |
| 1410 |
inline explicit C(int) {} |
| 1411 |
}; |
| 1412 |
} // namespace cwg194 |
| 1413 |
|
| 1414 |
namespace cwg195 { // cwg195: 2.7 |
| 1415 |
void f(); |
| 1416 |
int *p = (int*)&f; |
| 1417 |
// cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}} |
| 1418 |
void (*q)() = (void(*)())&p; |
| 1419 |
// cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}} |
| 1420 |
} // namespace cwg195 |
| 1421 |
|
| 1422 |
namespace cwg197 { // cwg197: 2.7 |
| 1423 |
char &f(char); |
| 1424 |
|
| 1425 |
template <class T> void g(T t) { |
| 1426 |
char &a = f(1); |
| 1427 |
char &b = f(T(1)); |
| 1428 |
// expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}} |
| 1429 |
// expected-note@#cwg197-g-e-call {{in instantiation of function template specialization 'cwg197::g<cwg197::E>' requested here}} |
| 1430 |
char &c = f(t); |
| 1431 |
// expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}} |
| 1432 |
} |
| 1433 |
|
| 1434 |
void f(int); |
| 1435 |
|
| 1436 |
enum E { e }; |
| 1437 |
int &f(E); |
| 1438 |
|
| 1439 |
void h() { |
| 1440 |
g('a'); |
| 1441 |
g(2); |
| 1442 |
g(e); // #cwg197-g-e-call |
| 1443 |
} |
| 1444 |
} // namespace cwg197 |
| 1445 |
|
| 1446 |
namespace cwg198 { // cwg198: 2.9 |
| 1447 |
struct A { |
| 1448 |
int n; |
| 1449 |
struct B { |
| 1450 |
int m[sizeof(n)]; |
| 1451 |
// cxx98-error@-1 {{invalid use of non-static data member 'n'}} |
| 1452 |
int f() { return n; } |
| 1453 |
// expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'B'}} |
| 1454 |
}; |
| 1455 |
struct C; |
| 1456 |
struct D; |
| 1457 |
}; |
| 1458 |
struct A::C { |
| 1459 |
int m[sizeof(n)]; |
| 1460 |
// cxx98-error@-1 {{invalid use of non-static data member 'n'}} |
| 1461 |
int f() { return n; } |
| 1462 |
// expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'C'}} |
| 1463 |
}; |
| 1464 |
struct A::D : A { |
| 1465 |
int m[sizeof(n)]; |
| 1466 |
// cxx98-error@-1 {{invalid use of non-static data member 'n'}} |
| 1467 |
int f() { return n; } |
| 1468 |
}; |
| 1469 |
} // namespace cwg198 |
| 1470 |
|
| 1471 |
// cwg199 is in cwg199.cpp |