| 1 |
// RUN: %clang_cc1 -std=c++98 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors |
| 2 |
// RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx11-17,since-cxx11, -fexceptions -fcxx-exceptions -pedantic-errors |
| 3 |
// RUN: %clang_cc1 -std=c++14 %s -verify=expected,cxx14-17,cxx11-17,since-cxx11,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors |
| 4 |
// RUN: %clang_cc1 -std=c++17 %s -verify=expected,cxx14-17,cxx11-17,since-cxx11,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors |
| 5 |
// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx14,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors |
| 6 |
// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx14,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors |
| 7 |
// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx14,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors |
| 8 |
|
| 9 |
// RUN: %clang_cc1 -std=c++98 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -fexperimental-new-constant-interpreter |
| 10 |
// RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx11-17,since-cxx11, -fexceptions -fcxx-exceptions -pedantic-errors -fexperimental-new-constant-interpreter |
| 11 |
// RUN: %clang_cc1 -std=c++14 %s -verify=expected,cxx14-17,cxx11-17,since-cxx11,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors -fexperimental-new-constant-interpreter |
| 12 |
// RUN: %clang_cc1 -std=c++17 %s -verify=expected,cxx14-17,cxx11-17,since-cxx11,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors -fexperimental-new-constant-interpreter |
| 13 |
// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx14,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors -fexperimental-new-constant-interpreter |
| 14 |
// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx14,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors -fexperimental-new-constant-interpreter |
| 15 |
// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx14,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors -fexperimental-new-constant-interpreter |
| 16 |
|
| 17 |
namespace cwg1413 { // cwg1413: 12 |
| 18 |
template<int> struct Check { |
| 19 |
typedef int type; |
| 20 |
}; |
| 21 |
template<typename T> struct A : T { |
| 22 |
static const int a = 1; |
| 23 |
static const int b; |
| 24 |
static void c(); |
| 25 |
void d(); |
| 26 |
|
| 27 |
void f() { |
| 28 |
Check<true ? 0 : A::unknown_spec>::type *var1; |
| 29 |
// expected-error@-1 {{use of undeclared identifier 'var1'}} |
| 30 |
|
| 31 |
// ok, variable declaration |
| 32 |
Check<true ? 0 : a>::type *var2; // #cwg1413-var2 |
| 33 |
Check<true ? 0 : b>::type *var3; |
| 34 |
// expected-error@-1 {{use of undeclared identifier 'var3'}} |
| 35 |
// expected-note@#cwg1413-var2 {{'var2' declared here}} |
| 36 |
Check<true ? 0 : ((void)c, 0)>::type *var4; |
| 37 |
// expected-error@-1 {{use of undeclared identifier 'var4'}} |
| 38 |
// expected-note@#cwg1413-var2 {{'var2' declared here}} |
| 39 |
|
| 40 |
// value-dependent because of the implied type-dependent 'this->', not because of 'd' |
| 41 |
Check<true ? 0 : (d(), 0)>::type *var5; |
| 42 |
// expected-error@-1 {{use of undeclared identifier 'var5'}} |
| 43 |
// expected-note@#cwg1413-var2 {{'var2' declared here}} |
| 44 |
|
| 45 |
// value-dependent because of the value-dependent '&' operator, not because of 'A::d' |
| 46 |
Check<true ? 0 : (&A::d(), 0)>::type *var5; |
| 47 |
// expected-error@-1 {{use of undeclared identifier 'var5'}} |
| 48 |
// expected-note@#cwg1413-var2 {{'var2' declared here}} |
| 49 |
} |
| 50 |
}; |
| 51 |
} // namespace cwg1413 |
| 52 |
|
| 53 |
namespace cwg1423 { // cwg1423: 11 |
| 54 |
#if __cplusplus >= 201103L |
| 55 |
bool b1 = nullptr; |
| 56 |
// since-cxx11-error@-1 {{cannot initialize a variable of type 'bool' with an rvalue of type 'std::nullptr_t'}} |
| 57 |
bool b2(nullptr); |
| 58 |
// since-cxx11-warning@-1 {{implicit conversion of nullptr constant to 'bool'}} |
| 59 |
bool b3 = {nullptr}; |
| 60 |
// since-cxx11-error@-1 {{cannot initialize a variable of type 'bool' with an rvalue of type 'std::nullptr_t'}} |
| 61 |
bool b4{nullptr}; |
| 62 |
// since-cxx11-warning@-1 {{implicit conversion of nullptr constant to 'bool'}} |
| 63 |
#endif |
| 64 |
} // namespace 1423 |
| 65 |
|
| 66 |
// cwg1425: na abi |
| 67 |
|
| 68 |
namespace cwg1432 { // cwg1432: 16 open 2022-11-11 |
| 69 |
#if __cplusplus >= 201103L |
| 70 |
namespace class_template_partial_spec { |
| 71 |
template<typename T> T declval(); |
| 72 |
|
| 73 |
template <class... T> |
| 74 |
struct common_type; |
| 75 |
|
| 76 |
template <class T, class U> |
| 77 |
struct common_type<T, U> { |
| 78 |
typedef decltype(true ? declval<T>() : declval<U>()) type; |
| 79 |
}; |
| 80 |
|
| 81 |
template <class T, class U, class... V> |
| 82 |
struct common_type<T, U, V...> { |
| 83 |
typedef typename common_type<typename common_type<T, U>::type, V...>::type type; |
| 84 |
}; |
| 85 |
|
| 86 |
template struct common_type<int, double>; |
| 87 |
} // namespace class_template_partial_spec |
| 88 |
namespace function_template { |
| 89 |
template <int I, class... Ts> struct A {}; |
| 90 |
|
| 91 |
template <int I, class... Ts> void f(A<I, Ts...>) = delete; |
| 92 |
template <int I> void f(A<I>); |
| 93 |
|
| 94 |
void test() { |
| 95 |
f(A<0>()); |
| 96 |
} |
| 97 |
} // namespace function_template |
| 98 |
#endif |
| 99 |
} // namespace cwg1432 |
| 100 |
|
| 101 |
namespace cwg1443 { // cwg1443: 2.7 |
| 102 |
struct A { |
| 103 |
int i; |
| 104 |
A() { void foo(int=i); } |
| 105 |
// expected-error@-1 {{default argument references 'this'}} |
| 106 |
}; |
| 107 |
} // namespace cwg1443 |
| 108 |
|
| 109 |
namespace cwg1458 { // cwg1458: 3.1 |
| 110 |
#if __cplusplus >= 201103L |
| 111 |
struct A; |
| 112 |
|
| 113 |
void f() { |
| 114 |
constexpr A* a = nullptr; |
| 115 |
constexpr int p = &*a; |
| 116 |
// since-cxx11-error@-1 {{cannot initialize a variable of type 'const int' with an rvalue of type 'A *'}} |
| 117 |
constexpr A *p2 = &*a; |
| 118 |
// since-cxx11-error@-1 {{constexpr variable 'p2' must be initialized by a constant expression}} |
| 119 |
// since-cxx11-note@-2 {{dereferencing a null pointer}} |
| 120 |
} |
| 121 |
|
| 122 |
struct A { |
| 123 |
int operator&(); |
| 124 |
}; |
| 125 |
#endif |
| 126 |
} // namespace cwg1458 |
| 127 |
|
| 128 |
namespace cwg1460 { // cwg1460: 3.5 |
| 129 |
#if __cplusplus >= 201103L |
| 130 |
namespace DRExample { |
| 131 |
union A { |
| 132 |
union {}; |
| 133 |
// since-cxx11-error@-1 {{declaration does not declare anything}} |
| 134 |
union {}; |
| 135 |
// since-cxx11-error@-1 {{declaration does not declare anything}} |
| 136 |
constexpr A() {} |
| 137 |
}; |
| 138 |
constexpr A a = A(); |
| 139 |
|
| 140 |
union B { |
| 141 |
union {}; |
| 142 |
// since-cxx11-error@-1 {{declaration does not declare anything}} |
| 143 |
union {}; |
| 144 |
// since-cxx11-error@-1 {{declaration does not declare anything}} |
| 145 |
constexpr B() = default; |
| 146 |
}; |
| 147 |
constexpr B b = B(); |
| 148 |
|
| 149 |
union C { |
| 150 |
union {}; |
| 151 |
// since-cxx11-error@-1 {{declaration does not declare anything}} |
| 152 |
union {}; |
| 153 |
// since-cxx11-error@-1 {{declaration does not declare anything}} |
| 154 |
}; |
| 155 |
constexpr C c = C(); |
| 156 |
#if __cplusplus >= 201403L |
| 157 |
constexpr void f() { C c; } |
| 158 |
static_assert((f(), true), ""); |
| 159 |
#endif |
| 160 |
} |
| 161 |
|
| 162 |
union A {}; |
| 163 |
union B { int n; }; // #cwg1460-B |
| 164 |
union C { int n = 0; }; |
| 165 |
struct D { union {}; }; |
| 166 |
// since-cxx11-error@-1 {{declaration does not declare anything}} |
| 167 |
struct E { union { int n; }; }; // #cwg1460-E |
| 168 |
struct F { union { int n = 0; }; }; |
| 169 |
|
| 170 |
struct X { |
| 171 |
friend constexpr A::A() noexcept; |
| 172 |
friend constexpr B::B() noexcept; |
| 173 |
// cxx11-17-error@-1 {{constexpr declaration of 'B' follows non-constexpr declaration}} |
| 174 |
// cxx11-17-note@#cwg1460-B {{previous declaration is here}} |
| 175 |
friend constexpr C::C() noexcept; |
| 176 |
friend constexpr D::D() noexcept; |
| 177 |
friend constexpr E::E() noexcept; |
| 178 |
// cxx11-17-error@-1 {{constexpr declaration of 'E' follows non-constexpr declaration}} |
| 179 |
// cxx11-17-note@#cwg1460-E {{previous declaration is here}} |
| 180 |
friend constexpr F::F() noexcept; |
| 181 |
}; |
| 182 |
|
| 183 |
// These are OK, because value-initialization doesn't actually invoke the |
| 184 |
// constructor. |
| 185 |
constexpr A a = A(); |
| 186 |
constexpr B b = B(); |
| 187 |
constexpr C c = C(); |
| 188 |
constexpr D d = D(); |
| 189 |
constexpr E e = E(); |
| 190 |
constexpr F f = F(); |
| 191 |
|
| 192 |
namespace Defaulted { |
| 193 |
union A { constexpr A() = default; }; |
| 194 |
union B { int n; constexpr B() = default; }; |
| 195 |
// cxx11-17-error@-1 {{defaulted definition of default constructor cannot be marked constexpr}} |
| 196 |
union C { int n = 0; constexpr C() = default; }; |
| 197 |
struct D { union {}; constexpr D() = default; }; |
| 198 |
// since-cxx11-error@-1 {{declaration does not declare anything}} |
| 199 |
struct E { union { int n; }; constexpr E() = default; }; |
| 200 |
// cxx11-17-error@-1 {{defaulted definition of default constructor cannot be marked constexpr}} |
| 201 |
struct F { union { int n = 0; }; constexpr F() = default; }; |
| 202 |
|
| 203 |
struct G { union { int n = 0; }; union { int m; }; constexpr G() = default; }; |
| 204 |
// cxx11-17-error@-1 {{defaulted definition of default constructor cannot be marked constexpr}} |
| 205 |
struct H { |
| 206 |
union { |
| 207 |
int n = 0; |
| 208 |
}; |
| 209 |
union { // #cwg1460-H-union |
| 210 |
int m; |
| 211 |
}; |
| 212 |
constexpr H() {} |
| 213 |
// cxx11-17-error@-1 {{constexpr constructor that does not initialize all members is a C++20 extension}} |
| 214 |
// cxx11-17-note@#cwg1460-H-union {{member not initialized by constructor}} |
| 215 |
constexpr H(bool) : m(1) {} |
| 216 |
constexpr H(char) : n(1) {} |
| 217 |
// cxx11-17-error@-1 {{constexpr constructor that does not initialize all members is a C++20 extension}} |
| 218 |
// cxx11-17-note@#cwg1460-H-union {{member not initialized by constructor}} |
| 219 |
constexpr H(double) : m(1), n(1) {} |
| 220 |
}; |
| 221 |
} |
| 222 |
|
| 223 |
#if __cplusplus >= 201403L |
| 224 |
template<typename T> constexpr bool check() { |
| 225 |
T t; // #cwg1460-t |
| 226 |
return true; |
| 227 |
} |
| 228 |
static_assert(check<A>(), ""); |
| 229 |
static_assert(check<B>(), ""); // #cwg1460-check-B |
| 230 |
// cxx14-17-error@-1 {{static assertion expression is not an integral constant expression}} |
| 231 |
// cxx14-17-note@#cwg1460-t {{non-constexpr constructor 'B' cannot be used in a constant expression}} |
| 232 |
// cxx14-17-note@#cwg1460-check-B {{in call to 'check<cwg1460::B>()'}} |
| 233 |
// cxx14-17-note@#cwg1460-B {{declared here}} |
| 234 |
static_assert(check<C>(), ""); |
| 235 |
static_assert(check<D>(), ""); |
| 236 |
static_assert(check<E>(), ""); // #cwg1460-check-E |
| 237 |
// cxx14-17-error@-1 {{static assertion expression is not an integral constant expression}} |
| 238 |
// cxx14-17-note@#cwg1460-t {{non-constexpr constructor 'E' cannot be used in a constant expression}} |
| 239 |
// cxx14-17-note@#cwg1460-check-E {{in call to 'check<cwg1460::E>()'}} |
| 240 |
// cxx14-17-note@#cwg1460-E {{declared here}} |
| 241 |
static_assert(check<F>(), ""); |
| 242 |
#endif |
| 243 |
|
| 244 |
union G { |
| 245 |
int a = 0; // #cwg1460-G-a |
| 246 |
int b = 0; |
| 247 |
// since-cxx11-error@-1 {{initializing multiple members of union}} |
| 248 |
// since-cxx11-note@#cwg1460-G-a {{previous initialization is here}} |
| 249 |
}; |
| 250 |
union H { |
| 251 |
union { |
| 252 |
int a = 0; // #cwg1460-H-a |
| 253 |
}; |
| 254 |
union { |
| 255 |
int b = 0; |
| 256 |
// since-cxx11-error@-1 {{initializing multiple members of union}} |
| 257 |
// since-cxx11-note@#cwg1460-H-a {{previous initialization is here}} |
| 258 |
}; |
| 259 |
}; |
| 260 |
struct I { |
| 261 |
union { |
| 262 |
int a = 0; // #cwg1460-I-a |
| 263 |
int b = 0; |
| 264 |
// since-cxx11-error@-1 {{initializing multiple members of union}} |
| 265 |
// since-cxx11-note@#cwg1460-I-a {{previous initialization is here}} |
| 266 |
}; |
| 267 |
}; |
| 268 |
struct J { |
| 269 |
union { int a = 0; }; |
| 270 |
union { int b = 0; }; |
| 271 |
}; |
| 272 |
|
| 273 |
namespace Overriding { |
| 274 |
struct A { |
| 275 |
int a = 1, b, c = 3; |
| 276 |
constexpr A() : b(2) {} |
| 277 |
}; |
| 278 |
static_assert(A().a == 1 && A().b == 2 && A().c == 3, ""); |
| 279 |
|
| 280 |
union B { |
| 281 |
int a, b = 2, c; |
| 282 |
constexpr B() : a(1) {} |
| 283 |
constexpr B(char) : b(4) {} |
| 284 |
constexpr B(int) : c(3) {} |
| 285 |
constexpr B(const char*) {} |
| 286 |
}; |
| 287 |
static_assert(B().a == 1, ""); |
| 288 |
static_assert(B().b == 2, ""); |
| 289 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 290 |
// since-cxx11-note@-2 {{read of member 'b' of union with active member 'a' is not allowed in a constant expression}} |
| 291 |
static_assert(B('x').a == 0, ""); |
| 292 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 293 |
// since-cxx11-note@-2 {{read of member 'a' of union with active member 'b' is not allowed in a constant expression}} |
| 294 |
static_assert(B('x').b == 4, ""); |
| 295 |
static_assert(B(123).b == 2, ""); |
| 296 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 297 |
// since-cxx11-note@-2 {{read of member 'b' of union with active member 'c' is not allowed in a constant expression}} |
| 298 |
static_assert(B(123).c == 3, ""); |
| 299 |
static_assert(B("").a == 1, ""); |
| 300 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 301 |
// since-cxx11-note@-2 {{read of member 'a' of union with active member 'b' is not allowed in a constant expression}} |
| 302 |
static_assert(B("").b == 2, ""); |
| 303 |
static_assert(B("").c == 3, ""); |
| 304 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 305 |
// since-cxx11-note@-2 {{read of member 'c' of union with active member 'b' is not allowed in a constant expression}} |
| 306 |
|
| 307 |
struct C { |
| 308 |
union { int a, b = 2, c; }; |
| 309 |
union { int d, e = 5, f; }; |
| 310 |
constexpr C() : a(1) {} |
| 311 |
constexpr C(char) : c(3) {} |
| 312 |
constexpr C(int) : d(4) {} |
| 313 |
constexpr C(float) : f(6) {} |
| 314 |
constexpr C(const char*) {} |
| 315 |
}; |
| 316 |
|
| 317 |
static_assert(C().a == 1, ""); |
| 318 |
static_assert(C().b == 2, ""); |
| 319 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 320 |
// since-cxx11-note@-2 {{read of member 'b' of union with active member 'a' is not allowed in a constant expression}} |
| 321 |
static_assert(C().d == 4, ""); |
| 322 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 323 |
// since-cxx11-note@-2 {{read of member 'd' of union with active member 'e' is not allowed in a constant expression}} |
| 324 |
static_assert(C().e == 5, ""); |
| 325 |
|
| 326 |
static_assert(C('x').b == 2, ""); |
| 327 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 328 |
// since-cxx11-note@-2 {{read of member 'b' of union with active member 'c' is not allowed in a constant expression}} |
| 329 |
static_assert(C('x').c == 3, ""); |
| 330 |
static_assert(C('x').d == 4, ""); |
| 331 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 332 |
// since-cxx11-note@-2 {{read of member 'd' of union with active member 'e' is not allowed in a constant expression}} |
| 333 |
static_assert(C('x').e == 5, ""); |
| 334 |
|
| 335 |
static_assert(C(1).b == 2, ""); |
| 336 |
static_assert(C(1).c == 3, ""); |
| 337 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 338 |
// since-cxx11-note@-2 {{read of member 'c' of union with active member 'b' is not allowed in a constant expression}} |
| 339 |
static_assert(C(1).d == 4, ""); |
| 340 |
static_assert(C(1).e == 5, ""); |
| 341 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 342 |
// since-cxx11-note@-2 {{read of member 'e' of union with active member 'd' is not allowed in a constant expression}} |
| 343 |
|
| 344 |
static_assert(C(1.f).b == 2, ""); |
| 345 |
static_assert(C(1.f).c == 3, ""); |
| 346 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 347 |
// since-cxx11-note@-2 {{read of member 'c' of union with active member 'b' is not allowed in a constant expression}} |
| 348 |
static_assert(C(1.f).e == 5, ""); |
| 349 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 350 |
// since-cxx11-note@-2 {{read of member 'e' of union with active member 'f' is not allowed in a constant expression}} |
| 351 |
static_assert(C(1.f).f == 6, ""); |
| 352 |
|
| 353 |
static_assert(C("").a == 1, ""); |
| 354 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 355 |
// since-cxx11-note@-2 {{read of member 'a' of union with active member 'b' is not allowed in a constant expression}} |
| 356 |
static_assert(C("").b == 2, ""); |
| 357 |
static_assert(C("").c == 3, ""); |
| 358 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 359 |
// since-cxx11-note@-2 {{read of member 'c' of union with active member 'b' is not allowed in a constant expression}} |
| 360 |
static_assert(C("").d == 4, ""); |
| 361 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 362 |
// since-cxx11-note@-2 {{read of member 'd' of union with active member 'e' is not allowed in a constant expression}} |
| 363 |
static_assert(C("").e == 5, ""); |
| 364 |
static_assert(C("").f == 6, ""); |
| 365 |
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}} |
| 366 |
// since-cxx11-note@-2 {{read of member 'f' of union with active member 'e' is not allowed in a constant expression}} |
| 367 |
|
| 368 |
struct D; |
| 369 |
extern const D d; |
| 370 |
struct D { |
| 371 |
int a; |
| 372 |
union { |
| 373 |
int b = const_cast<D&>(d).a = 1; // not evaluated |
| 374 |
int c; |
| 375 |
}; |
| 376 |
constexpr D() : a(0), c(0) {} |
| 377 |
}; |
| 378 |
constexpr D d {}; |
| 379 |
static_assert(d.a == 0, ""); |
| 380 |
} |
| 381 |
#endif |
| 382 |
} // namespace cwg1460 |
| 383 |
|
| 384 |
#if __cplusplus >= 201103L |
| 385 |
namespace std { |
| 386 |
typedef decltype(sizeof(int)) size_t; |
| 387 |
|
| 388 |
// libc++'s implementation |
| 389 |
template <class _E> |
| 390 |
class initializer_list |
| 391 |
{ |
| 392 |
const _E* __begin_; |
| 393 |
size_t __size_; |
| 394 |
|
| 395 |
initializer_list(const _E* __b, size_t __s) |
| 396 |
: __begin_(__b), __size_(__s) {} |
| 397 |
|
| 398 |
public: |
| 399 |
typedef _E value_type; |
| 400 |
typedef const _E& reference; |
| 401 |
typedef const _E& const_reference; |
| 402 |
typedef size_t size_type; |
| 403 |
|
| 404 |
typedef const _E* iterator; |
| 405 |
typedef const _E* const_iterator; |
| 406 |
|
| 407 |
initializer_list() : __begin_(nullptr), __size_(0) {} |
| 408 |
|
| 409 |
size_t size() const {return __size_;} |
| 410 |
const _E* begin() const {return __begin_;} |
| 411 |
const _E* end() const {return __begin_ + __size_;} |
| 412 |
}; |
| 413 |
} // namespace std |
| 414 |
#endif |
| 415 |
|
| 416 |
namespace cwg1467 { // cwg1467: 3.7 c++11 |
| 417 |
#if __cplusplus >= 201103L |
| 418 |
// Note that the change to [over.best.ics] was partially undone by CWG2076; |
| 419 |
// the resulting rule is tested with the tests for that change. |
| 420 |
|
| 421 |
// List-initialization of aggregate from same-type object |
| 422 |
|
| 423 |
namespace basic0 { |
| 424 |
struct S { |
| 425 |
int i = 42; |
| 426 |
}; |
| 427 |
|
| 428 |
S a; |
| 429 |
S b(a); |
| 430 |
S c{a}; |
| 431 |
|
| 432 |
struct SS : public S { } x; |
| 433 |
S y(x); |
| 434 |
S z{x}; |
| 435 |
} // basic0 |
| 436 |
|
| 437 |
namespace basic1 { |
| 438 |
struct S { |
| 439 |
int i{42}; |
| 440 |
}; |
| 441 |
|
| 442 |
S a; |
| 443 |
S b(a); |
| 444 |
S c{a}; |
| 445 |
|
| 446 |
struct SS : public S { } x; |
| 447 |
S y(x); |
| 448 |
S z{x}; |
| 449 |
} // basic1 |
| 450 |
|
| 451 |
namespace basic2 { |
| 452 |
struct S { |
| 453 |
int i = {42}; |
| 454 |
}; |
| 455 |
|
| 456 |
S a; |
| 457 |
S b(a); |
| 458 |
S c{a}; |
| 459 |
|
| 460 |
struct SS : public S { } x; |
| 461 |
S y(x); |
| 462 |
S z{x}; |
| 463 |
} // basic2 |
| 464 |
|
| 465 |
namespace dr_example { |
| 466 |
struct OK { |
| 467 |
OK() = default; |
| 468 |
OK(const OK&) = default; |
| 469 |
OK(int) { } |
| 470 |
}; |
| 471 |
|
| 472 |
OK ok; |
| 473 |
OK ok2{ok}; |
| 474 |
|
| 475 |
struct X { |
| 476 |
X() = default; |
| 477 |
X(const X&) = default; |
| 478 |
}; |
| 479 |
|
| 480 |
X x; |
| 481 |
X x2{x}; |
| 482 |
|
| 483 |
void f1(int); // #cwg1467-f1 |
| 484 |
void f1(std::initializer_list<long>) = delete; // #cwg1467-f1-deleted |
| 485 |
void g1() { f1({42}); } |
| 486 |
// since-cxx11-error@-1 {{call to deleted function 'f1'}} |
| 487 |
// since-cxx11-note@#cwg1467-f1 {{candidate function}} |
| 488 |
// since-cxx11-note@#cwg1467-f1-deleted {{candidate function has been explicitly deleted}} |
| 489 |
|
| 490 |
template <class T, class U> |
| 491 |
struct Pair { |
| 492 |
Pair(T, U); |
| 493 |
}; |
| 494 |
struct String { |
| 495 |
String(const char *); |
| 496 |
}; |
| 497 |
|
| 498 |
void f2(Pair<const char *, const char *>); // #cwg1467-f2 |
| 499 |
void f2(std::initializer_list<String>) = delete; // #cwg1467-f2-deleted |
| 500 |
void g2() { f2({"foo", "bar"}); } |
| 501 |
// since-cxx11-error@-1 {{call to deleted function 'f2'}} |
| 502 |
// since-cxx11-note@#cwg1467-f2 {{candidate function}} |
| 503 |
// since-cxx11-note@#cwg1467-f2-deleted {{candidate function has been explicitly deleted}} |
| 504 |
} // dr_example |
| 505 |
|
| 506 |
namespace nonaggregate { |
| 507 |
struct NonAggregate { |
| 508 |
NonAggregate() {} |
| 509 |
}; |
| 510 |
|
| 511 |
struct WantsIt { |
| 512 |
WantsIt(NonAggregate); |
| 513 |
}; |
| 514 |
|
| 515 |
void f(NonAggregate); |
| 516 |
void f(WantsIt); |
| 517 |
|
| 518 |
void test1() { |
| 519 |
NonAggregate n; |
| 520 |
f({n}); |
| 521 |
} |
| 522 |
|
| 523 |
void test2() { |
| 524 |
NonAggregate x; |
| 525 |
NonAggregate y{x}; |
| 526 |
NonAggregate z{{x}}; |
| 527 |
} |
| 528 |
} // nonaggregate |
| 529 |
|
| 530 |
struct NestedInit { int a, b, c; }; |
| 531 |
NestedInit ni[1] = {{NestedInit{1, 2, 3}}}; |
| 532 |
|
| 533 |
namespace NestedInit2 { |
| 534 |
struct Pair { int a, b; }; |
| 535 |
struct TwoPairs { TwoPairs(Pair, Pair); }; |
| 536 |
struct Value { Value(Pair); Value(TwoPairs); }; |
| 537 |
void f() { Value{{{1,2},{3,4}}}; } |
| 538 |
} |
| 539 |
namespace NonAmbiguous { |
| 540 |
// The original implementation made this case ambiguous due to the special |
| 541 |
// handling of one element initialization lists. |
| 542 |
void f(int(&&)[1]); |
| 543 |
void f(unsigned(&&)[1]); |
| 544 |
|
| 545 |
void g(unsigned i) { |
| 546 |
f({i}); |
| 547 |
} |
| 548 |
} // namespace NonAmbiguous |
| 549 |
|
| 550 |
namespace StringLiterals { |
| 551 |
// When the array size is 4 the call will attempt to bind an lvalue to an |
| 552 |
// rvalue and fail. Therefore #2 will be called. (rsmith will bring this |
| 553 |
// issue to CWG) |
| 554 |
void f(const char(&&)[4]); // #cwg1467-f-char-4 |
| 555 |
void f(const char(&&)[5]) = delete; // #cwg1467-f-char-5 |
| 556 |
void f(const wchar_t(&&)[4]); // #cwg1467-f-wchar-4 |
| 557 |
void f(const wchar_t(&&)[5]) = delete; // #cwg1467-f-wchar-5 |
| 558 |
#if __cplusplus >= 202002L |
| 559 |
void f2(const char8_t(&&)[4]); // #cwg1467-f2-char8-4 |
| 560 |
void f2(const char8_t(&&)[5]) = delete; // #cwg1467-f2-char8-5 |
| 561 |
#endif |
| 562 |
void f(const char16_t(&&)[4]); // #cwg1467-f-char16-4 |
| 563 |
void f(const char16_t(&&)[5]) = delete; // #cwg1467-f-char16-5 |
| 564 |
void f(const char32_t(&&)[4]); // #cwg1467-f-char32-4 |
| 565 |
void f(const char32_t(&&)[5]) = delete; // #cwg1467-f-char32-5 |
| 566 |
void g() { |
| 567 |
f({"abc"}); |
| 568 |
// since-cxx11-error@-1 {{call to deleted function 'f'}} |
| 569 |
// since-cxx11-note@#cwg1467-f-char-5 {{candidate function has been explicitly deleted}} |
| 570 |
// since-cxx11-note@#cwg1467-f-char-4 {{candidate function not viable: expects an rvalue for 1st argument}} |
| 571 |
// since-cxx11-note@#cwg1467-f-wchar-4 {{candidate function not viable: no known conversion from 'const char[4]' to 'const wchar_t' for 1st argument}} |
| 572 |
// since-cxx11-note@#cwg1467-f-wchar-5 {{candidate function not viable: no known conversion from 'const char[4]' to 'const wchar_t' for 1st argument}} |
| 573 |
// since-cxx11-note@#cwg1467-f-char16-4 {{candidate function not viable: no known conversion from 'const char[4]' to 'const char16_t' for 1st argument}} |
| 574 |
// since-cxx11-note@#cwg1467-f-char16-5 {{candidate function not viable: no known conversion from 'const char[4]' to 'const char16_t' for 1st argument}} |
| 575 |
// since-cxx11-note@#cwg1467-f-char32-4 {{candidate function not viable: no known conversion from 'const char[4]' to 'const char32_t' for 1st argument}} |
| 576 |
// since-cxx11-note@#cwg1467-f-char32-5 {{candidate function not viable: no known conversion from 'const char[4]' to 'const char32_t' for 1st argument}} |
| 577 |
f({((("abc")))}); |
| 578 |
// since-cxx11-error@-1 {{call to deleted function 'f'}} |
| 579 |
// since-cxx11-note@#cwg1467-f-char-5 {{candidate function has been explicitly deleted}} |
| 580 |
// since-cxx11-note@#cwg1467-f-char-4 {{candidate function not viable: expects an rvalue for 1st argument}} |
| 581 |
// since-cxx11-note@#cwg1467-f-wchar-4 {{candidate function not viable: no known conversion from 'const char[4]' to 'const wchar_t' for 1st argument}} |
| 582 |
// since-cxx11-note@#cwg1467-f-wchar-5 {{candidate function not viable: no known conversion from 'const char[4]' to 'const wchar_t' for 1st argument}} |
| 583 |
// since-cxx11-note@#cwg1467-f-char16-4 {{candidate function not viable: no known conversion from 'const char[4]' to 'const char16_t' for 1st argument}} |
| 584 |
// since-cxx11-note@#cwg1467-f-char16-5 {{candidate function not viable: no known conversion from 'const char[4]' to 'const char16_t' for 1st argument}} |
| 585 |
// since-cxx11-note@#cwg1467-f-char32-4 {{candidate function not viable: no known conversion from 'const char[4]' to 'const char32_t' for 1st argument}} |
| 586 |
// since-cxx11-note@#cwg1467-f-char32-5 {{candidate function not viable: no known conversion from 'const char[4]' to 'const char32_t' for 1st argument}} |
| 587 |
f({L"abc"}); |
| 588 |
// since-cxx11-error@-1 {{call to deleted function 'f'}} |
| 589 |
// since-cxx11-note@#cwg1467-f-wchar-5 {{candidate function has been explicitly deleted}} |
| 590 |
// since-cxx11-note@#cwg1467-f-char-4 {{candidate function not viable: no known conversion from 'const wchar_t[4]' to 'const char' for 1st argument}} |
| 591 |
// since-cxx11-note@#cwg1467-f-char-5 {{candidate function not viable: no known conversion from 'const wchar_t[4]' to 'const char' for 1st argument}} |
| 592 |
// since-cxx11-note@#cwg1467-f-wchar-4 {{candidate function not viable: expects an rvalue for 1st argument}} |
| 593 |
// since-cxx11-note@#cwg1467-f-char16-4 {{candidate function not viable: no known conversion from 'const wchar_t[4]' to 'const char16_t' for 1st argument}} |
| 594 |
// since-cxx11-note@#cwg1467-f-char16-5 {{candidate function not viable: no known conversion from 'const wchar_t[4]' to 'const char16_t' for 1st argument}} |
| 595 |
// since-cxx11-note@#cwg1467-f-char32-4 {{candidate function not viable: no known conversion from 'const wchar_t[4]' to 'const char32_t' for 1st argument}} |
| 596 |
// since-cxx11-note@#cwg1467-f-char32-5 {{candidate function not viable: no known conversion from 'const wchar_t[4]' to 'const char32_t' for 1st argument}} |
| 597 |
#if __cplusplus >= 202002L |
| 598 |
f2({u8"abc"}); |
| 599 |
// since-cxx20-error@-1 {{call to deleted function 'f2'}} |
| 600 |
// since-cxx20-note@#cwg1467-f2-char8-5 {{candidate function has been explicitly deleted}} |
| 601 |
// since-cxx20-note@#cwg1467-f2-char8-4 {{candidate function not viable: expects an rvalue for 1st argument}} |
| 602 |
#endif |
| 603 |
f({uR"(abc)"}); |
| 604 |
// since-cxx11-error@-1 {{call to deleted function 'f'}} |
| 605 |
// since-cxx11-note@#cwg1467-f-char16-5 {{candidate function has been explicitly deleted}} |
| 606 |
// since-cxx11-note@#cwg1467-f-char-4 {{candidate function not viable: no known conversion from 'const char16_t[4]' to 'const char' for 1st argument}} |
| 607 |
// since-cxx11-note@#cwg1467-f-char-5 {{candidate function not viable: no known conversion from 'const char16_t[4]' to 'const char' for 1st argument}} |
| 608 |
// since-cxx11-note@#cwg1467-f-wchar-4 {{candidate function not viable: no known conversion from 'const char16_t[4]' to 'const wchar_t' for 1st argument}} |
| 609 |
// since-cxx11-note@#cwg1467-f-wchar-5 {{candidate function not viable: no known conversion from 'const char16_t[4]' to 'const wchar_t' for 1st argument}} |
| 610 |
// since-cxx11-note@#cwg1467-f-char16-4 {{candidate function not viable: expects an rvalue for 1st argument}} |
| 611 |
// since-cxx11-note@#cwg1467-f-char32-4 {{candidate function not viable: no known conversion from 'const char16_t[4]' to 'const char32_t' for 1st argument}} |
| 612 |
// since-cxx11-note@#cwg1467-f-char32-5 {{candidate function not viable: no known conversion from 'const char16_t[4]' to 'const char32_t' for 1st argument}} |
| 613 |
f({(UR"(abc)")}); |
| 614 |
// since-cxx11-error@-1 {{call to deleted function 'f'}} |
| 615 |
// since-cxx11-note@#cwg1467-f-char32-5 {{candidate function has been explicitly deleted}} |
| 616 |
// since-cxx11-note@#cwg1467-f-char-4 {{candidate function not viable: no known conversion from 'const char32_t[4]' to 'const char' for 1st argument}} |
| 617 |
// since-cxx11-note@#cwg1467-f-char-5 {{candidate function not viable: no known conversion from 'const char32_t[4]' to 'const char' for 1st argument}} |
| 618 |
// since-cxx11-note@#cwg1467-f-wchar-4 {{candidate function not viable: no known conversion from 'const char32_t[4]' to 'const wchar_t' for 1st argument}} |
| 619 |
// since-cxx11-note@#cwg1467-f-wchar-5 {{candidate function not viable: no known conversion from 'const char32_t[4]' to 'const wchar_t' for 1st argument}} |
| 620 |
// since-cxx11-note@#cwg1467-f-char16-4 {{candidate function not viable: no known conversion from 'const char32_t[4]' to 'const char16_t' for 1st argument}} |
| 621 |
// since-cxx11-note@#cwg1467-f-char16-5 {{candidate function not viable: no known conversion from 'const char32_t[4]' to 'const char16_t' for 1st argument}} |
| 622 |
// since-cxx11-note@#cwg1467-f-char32-4 {{candidate function not viable: expects an rvalue for 1st argument}} |
| 623 |
} |
| 624 |
} // namespace StringLiterals |
| 625 |
#endif |
| 626 |
} // namespace cwg1467 |
| 627 |
|
| 628 |
namespace cwg1477 { // cwg1477: 2.7 |
| 629 |
namespace N { |
| 630 |
struct A { |
| 631 |
// Name "f" is not bound in N, |
| 632 |
// so single searches of 'f' in N won't find it, |
| 633 |
// but the targets scope of this declaration is N, |
| 634 |
// making it nominable in N. |
| 635 |
// (_N4988_.[dcl.meaning]/2.1, [basic.scope.scope]/7, |
| 636 |
// [basic.lookup.general]/3) |
| 637 |
friend int f(); |
| 638 |
}; |
| 639 |
} |
| 640 |
// Corresponds to the friend declaration, |
| 641 |
// because it's nominable in N, |
| 642 |
// and binds name 'f' in N. |
| 643 |
// (_N4988_.[dcl.meaning]/3.4, [basic.scope.scope]/2.5) |
| 644 |
int N::f() { return 0; } |
| 645 |
// Name 'f' is bound in N, |
| 646 |
// so the search performed by qualified lookup finds it. |
| 647 |
int i = N::f(); |
| 648 |
} // namespace cwg1477 |
| 649 |
|
| 650 |
namespace cwg1479 { // cwg1479: 3.1 |
| 651 |
#if __cplusplus >= 201103L |
| 652 |
int operator""_a(const char*, std::size_t = 0); |
| 653 |
// since-cxx11-error@-1 {{literal operator cannot have a default argument}} |
| 654 |
#endif |
| 655 |
} // namespace cwg1479 |
| 656 |
|
| 657 |
namespace cwg1482 { // cwg1482: 3.0 |
| 658 |
// NB: sup 2516, test reused there |
| 659 |
#if __cplusplus >= 201103L |
| 660 |
template <typename T> struct S { |
| 661 |
typedef char I; |
| 662 |
}; |
| 663 |
enum E2 : S<E2>::I { e }; |
| 664 |
// since-cxx11-error@-1 {{use of undeclared identifier 'E2'}} |
| 665 |
#endif |
| 666 |
} // namespace cwg1482 |
| 667 |
|
| 668 |
namespace cwg1487 { // cwg1487: 3.3 |
| 669 |
#if __cplusplus >= 201103L |
| 670 |
struct A { // #cwg1482-A |
| 671 |
struct B { |
| 672 |
using A::A; |
| 673 |
// since-cxx11-error@-1 {{using declaration refers into 'A', which is not a base class of 'B'}} |
| 674 |
}; |
| 675 |
|
| 676 |
struct C : A { |
| 677 |
// since-cxx11-error@-1 {{base class has incomplete type}} |
| 678 |
// since-cxx11-note@#cwg1482-A {{definition of 'cwg1487::A' is not complete until the closing '}'}} |
| 679 |
using A::A; |
| 680 |
// since-cxx11-error@-1 {{using declaration refers into 'A', which is not a base class of 'C'}} |
| 681 |
}; |
| 682 |
|
| 683 |
struct D; |
| 684 |
}; |
| 685 |
|
| 686 |
struct D : A { |
| 687 |
using A::A; |
| 688 |
}; |
| 689 |
#endif |
| 690 |
} // namespace cwg1487 |
| 691 |
|
| 692 |
namespace cwg1490 { // cwg1490: 3.7 c++11 |
| 693 |
#if __cplusplus >= 201103L |
| 694 |
// List-initialization from a string literal |
| 695 |
|
| 696 |
char s[4]{"abc"}; // Ok |
| 697 |
std::initializer_list<char>{"abc"}; |
| 698 |
// since-cxx11-error@-1 {{expected unqualified-id}}} |
| 699 |
#endif |
| 700 |
} // namespace cwg1490 |
| 701 |
|
| 702 |
namespace cwg1495 { // cwg1495: 4 |
| 703 |
#if __cplusplus >= 201103L |
| 704 |
// Deduction succeeds in both directions. |
| 705 |
template<typename T, typename U> struct A {}; // #cwg1495-A |
| 706 |
template<typename T, typename U> struct A<U, T> {}; |
| 707 |
// since-cxx11-error@-1 {{class template partial specialization is not more specialized than the primary template}} |
| 708 |
// since-cxx11-note@#cwg1495-A {{template is declared here}} |
| 709 |
|
| 710 |
// Primary template is more specialized. |
| 711 |
template<typename, typename...> struct B {}; // #cwg1495-B |
| 712 |
template<typename ...Ts> struct B<Ts...> {}; |
| 713 |
// since-cxx11-error@-1 {{class template partial specialization is not more specialized than the primary template}} |
| 714 |
// since-cxx11-note@#cwg1495-B {{template is declared here}} |
| 715 |
|
| 716 |
// Deduction fails in both directions. |
| 717 |
template<int, typename, typename ...> struct C {}; // #cwg1495-C |
| 718 |
template<typename ...Ts> struct C<0, Ts...> {}; |
| 719 |
// since-cxx11-error@-1 {{class template partial specialization is not more specialized than the primary template}} |
| 720 |
// since-cxx11-note@#cwg1495-C {{template is declared here}} |
| 721 |
|
| 722 |
#if __cplusplus >= 201402L |
| 723 |
// Deduction succeeds in both directions. |
| 724 |
template<typename T, typename U> int a; // #cwg1495-a |
| 725 |
template<typename T, typename U> int a<U, T>; |
| 726 |
// since-cxx14-error@-1 {{variable template partial specialization is not more specialized than the primary template}} |
| 727 |
// since-cxx14-note@#cwg1495-a {{template is declared here}} |
| 728 |
|
| 729 |
// Primary template is more specialized. |
| 730 |
template<typename, typename...> int b; // #cwg1495-b |
| 731 |
template<typename ...Ts> int b<Ts...>; |
| 732 |
// since-cxx14-error@-1 {{variable template partial specialization is not more specialized than the primary template}} |
| 733 |
// since-cxx14-note@#cwg1495-b {{template is declared here}} |
| 734 |
|
| 735 |
// Deduction fails in both directions. |
| 736 |
template<int, typename, typename ...> int c; // #cwg1495-c |
| 737 |
template<typename ...Ts> int c<0, Ts...>; |
| 738 |
// since-cxx14-error@-1 {{variable template partial specialization is not more specialized than the primary template}} |
| 739 |
// since-cxx14-note@#cwg1495-c {{template is declared here}} |
| 740 |
#endif |
| 741 |
#endif |
| 742 |
} // namespace cwg1495 |
| 743 |
|
| 744 |
namespace cwg1496 { // cwg1496: no |
| 745 |
#if __cplusplus >= 201103L |
| 746 |
struct A { |
| 747 |
A() = delete; |
| 748 |
}; |
| 749 |
// FIXME: 'A' should not be trivial because the class lacks at least one |
| 750 |
// default constructor which is not deleted. |
| 751 |
static_assert(__is_trivial(A), ""); |
| 752 |
#endif |
| 753 |
} // namespace cwg1496 |