|
1 |
| -// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify |
2 |
| -// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated |
3 |
| -// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter %s -verify |
4 |
| -// RUN: %clang_cc1 -std=c++20 -verify=ref %s -Wno-constant-evaluated |
5 |
| -// RUN: %clang_cc1 -triple avr -std=c++20 -fexperimental-new-constant-interpreter %s -verify |
6 |
| -// RUN: %clang_cc1 -triple avr -std=c++20 -verify=ref %s -Wno-constant-evaluated |
| 1 | +// RUN: %clang_cc1 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify |
| 2 | +// RUN: %clang_cc1 -Wno-string-plus-int -fexperimental-new-constant-interpreter -triple i686 %s -verify |
| 3 | +// RUN: %clang_cc1 -Wno-string-plus-int -verify=ref %s -Wno-constant-evaluated |
| 4 | +// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify |
| 5 | +// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter -triple i686 %s -verify |
| 6 | +// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -verify=ref %s -Wno-constant-evaluated |
| 7 | +// RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify |
| 8 | +// RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int -verify=ref %s -Wno-constant-evaluated |
7 | 9 |
|
8 | 10 |
|
9 | 11 | namespace strcmp {
|
@@ -40,6 +42,70 @@ namespace strcmp {
|
40 | 42 | // ref-note {{dereferenced one-past-the-end}}
|
41 | 43 | }
|
42 | 44 |
|
| 45 | +/// Copied from constant-expression-cxx11.cpp |
| 46 | +namespace strlen { |
| 47 | +constexpr const char *a = "foo\0quux"; |
| 48 | + constexpr char b[] = "foo\0quux"; |
| 49 | + constexpr int f() { return 'u'; } |
| 50 | + constexpr char c[] = { 'f', 'o', 'o', 0, 'q', f(), 'u', 'x', 0 }; |
| 51 | + |
| 52 | + static_assert(__builtin_strlen("foo") == 3, ""); |
| 53 | + static_assert(__builtin_strlen("foo\0quux") == 3, ""); |
| 54 | + static_assert(__builtin_strlen("foo\0quux" + 4) == 4, ""); |
| 55 | + |
| 56 | + constexpr bool check(const char *p) { |
| 57 | + return __builtin_strlen(p) == 3 && |
| 58 | + __builtin_strlen(p + 1) == 2 && |
| 59 | + __builtin_strlen(p + 2) == 1 && |
| 60 | + __builtin_strlen(p + 3) == 0 && |
| 61 | + __builtin_strlen(p + 4) == 4 && |
| 62 | + __builtin_strlen(p + 5) == 3 && |
| 63 | + __builtin_strlen(p + 6) == 2 && |
| 64 | + __builtin_strlen(p + 7) == 1 && |
| 65 | + __builtin_strlen(p + 8) == 0; |
| 66 | + } |
| 67 | + |
| 68 | + static_assert(check(a), ""); |
| 69 | + static_assert(check(b), ""); |
| 70 | + static_assert(check(c), ""); |
| 71 | + |
| 72 | + constexpr int over1 = __builtin_strlen(a + 9); // expected-error {{constant expression}} \ |
| 73 | + // expected-note {{one-past-the-end}} \ |
| 74 | + // expected-note {{in call to}} \ |
| 75 | + // ref-error {{constant expression}} \ |
| 76 | + // ref-note {{one-past-the-end}} |
| 77 | + constexpr int over2 = __builtin_strlen(b + 9); // expected-error {{constant expression}} \ |
| 78 | + // expected-note {{one-past-the-end}} \ |
| 79 | + // expected-note {{in call to}} \ |
| 80 | + // ref-error {{constant expression}} \ |
| 81 | + // ref-note {{one-past-the-end}} |
| 82 | + constexpr int over3 = __builtin_strlen(c + 9); // expected-error {{constant expression}} \ |
| 83 | + // expected-note {{one-past-the-end}} \ |
| 84 | + // expected-note {{in call to}} \ |
| 85 | + // ref-error {{constant expression}} \ |
| 86 | + // ref-note {{one-past-the-end}} |
| 87 | + |
| 88 | + constexpr int under1 = __builtin_strlen(a - 1); // expected-error {{constant expression}} \ |
| 89 | + // expected-note {{cannot refer to element -1}} \ |
| 90 | + // ref-error {{constant expression}} \ |
| 91 | + // ref-note {{cannot refer to element -1}} |
| 92 | + constexpr int under2 = __builtin_strlen(b - 1); // expected-error {{constant expression}} \ |
| 93 | + // expected-note {{cannot refer to element -1}} \ |
| 94 | + // ref-error {{constant expression}} \ |
| 95 | + // ref-note {{cannot refer to element -1}} |
| 96 | + constexpr int under3 = __builtin_strlen(c - 1); // expected-error {{constant expression}} \ |
| 97 | + // expected-note {{cannot refer to element -1}} \ |
| 98 | + // ref-error {{constant expression}} \ |
| 99 | + // ref-note {{cannot refer to element -1}} |
| 100 | + |
| 101 | + constexpr char d[] = { 'f', 'o', 'o' }; // no nul terminator. |
| 102 | + constexpr int bad = __builtin_strlen(d); // expected-error {{constant expression}} \ |
| 103 | + // expected-note {{one-past-the-end}} \ |
| 104 | + // expected-note {{in call to}} \ |
| 105 | + // ref-error {{constant expression}} \ |
| 106 | + // ref-note {{one-past-the-end}} |
| 107 | +} |
| 108 | + |
43 | 109 | namespace nan {
|
44 | 110 | constexpr double NaN1 = __builtin_nan("");
|
45 | 111 |
|
|
0 commit comments