|
2 | 2 | // RUN: %clang_cc1 -std=c++2c -triple=x86_64-linux -fsyntax-only %s -verify -fexperimental-new-constant-interpreter |
3 | 3 |
|
4 | 4 | static_assert(true, ""); |
5 | | -static_assert(true, 0); // expected-error {{the message in a static assertion must be a string literal or an object with 'data()' and 'size()' member functions}} |
| 5 | +static_assert(true, 0); // expected-error {{the message in a static assertion must be a null terminated constant string or an object with 'data()' and 'size()' member functions}} |
6 | 6 | struct Empty{}; |
7 | 7 | static_assert(true, Empty{}); // expected-error {{the message object in this static assertion is missing 'data()' and 'size()' member functions}} |
8 | 8 | struct NoData { |
@@ -288,7 +288,7 @@ struct Good { |
288 | 288 |
|
289 | 289 | template <typename Ty> |
290 | 290 | struct Bad { |
291 | | - static_assert(false, Ty{}); // expected-error {{the message in a static assertion must be a string literal or an object with 'data()' and 'size()' member functions}} \ |
| 291 | + static_assert(false, Ty{}); // expected-error {{the message in a static assertion must be a null terminated constant string or an object with 'data()' and 'size()' member functions}} \ |
292 | 292 | // expected-error {{static assertion failed}} |
293 | 293 | }; |
294 | 294 |
|
@@ -416,3 +416,50 @@ static_assert( |
416 | 416 | // expected-note@-1 {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}} |
417 | 417 | ); |
418 | 418 | } |
| 419 | + |
| 420 | +static_assert(false, &(" basic test"[1])); |
| 421 | +// expected-error@-1 {{static assertion failed: basic test}} |
| 422 | +// expected-warning@-2 {{consteval string constants are an extension}} |
| 423 | + |
| 424 | +constexpr const char *constexpr_global = "global_constexpr"; |
| 425 | +constexpr const char null_terminated_buffer[] = { 'n', 'u', 'l', 'l', 't', 'e', 'r', 'm', 0 }; |
| 426 | +constexpr const char no_null_buffer[] = { 'n', 'o', 'n', 'u', 'l', 'l', 't', 'e', 'r', 'm' }; |
| 427 | + |
| 428 | +constexpr const char *selector(int i) { |
| 429 | + constexpr const char * a_constant = "a_constant"; |
| 430 | + const char *non_constexpr = "non-constexpr string"; |
| 431 | + switch (i) { |
| 432 | + case 0: return "case 0"; |
| 433 | + case 1: return a_constant; |
| 434 | + case 2: return constexpr_global; |
| 435 | + case 3: return null_terminated_buffer; |
| 436 | + case 4: return &(""[1]); // point to after the null terminator |
| 437 | + case 5: return nullptr; |
| 438 | + case 6: return no_null_buffer; |
| 439 | + } |
| 440 | +}; |
| 441 | + |
| 442 | +static_assert(false, selector(0)); |
| 443 | +// expected-error@-1 {{static assertion failed: case 0}} |
| 444 | +// expected-warning@-2 {{consteval string constants are an extension}} |
| 445 | +static_assert(false, selector(1)); |
| 446 | +// expected-error@-1 {{static assertion failed: a_constant}} |
| 447 | +// expected-warning@-2 {{consteval string constants are an extension}} |
| 448 | +static_assert(false, selector(2)); |
| 449 | +// expected-error@-1 {{static assertion failed: global_constexpr}} |
| 450 | +// expected-warning@-2 {{consteval string constants are an extension}} |
| 451 | +static_assert(false, selector(3)); |
| 452 | +// expected-error@-1 {{static assertion failed: nullterm}} |
| 453 | +// expected-warning@-2 {{consteval string constants are an extension}} |
| 454 | +static_assert(false, selector(4)); |
| 455 | +// expected-error@-1 {{the message in a static assertion is not null terminated}} |
| 456 | +// expected-error@-2 {{static assertion failed}} |
| 457 | +static_assert(false, selector(5)); |
| 458 | +// expected-error@-1 {{the message in a static assertion is not null terminated}} |
| 459 | +// expected-error@-2 {{static assertion failed}} |
| 460 | +static_assert(false, selector(6)); |
| 461 | +// expected-error@-1 {{the message in a static assertion is not null terminated}} |
| 462 | +// expected-error@-2 {{static assertion failed}} |
| 463 | +static_assert(false, selector(7)); |
| 464 | +// expected-error@-1 {{the message in a static assertion is not null terminated}} |
| 465 | +// expected-error@-2 {{static assertion failed}} |
0 commit comments