| 1 |
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify %s |
| 2 |
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify %s |
| 3 |
|
| 4 |
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify %s -fexperimental-new-constant-interpreter |
| 5 |
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify %s -fexperimental-new-constant-interpreter |
| 6 |
|
| 7 |
#if !__has_builtin(__builtin_verbose_trap) |
| 8 |
#error |
| 9 |
#endif |
| 10 |
|
| 11 |
constexpr char const* constCat1 = "cat"; |
| 12 |
char const* const constCat2 = "cat"; |
| 13 |
char const constCat3[] = "cat"; |
| 14 |
|
| 15 |
constexpr char const* constMsg1 = "hello"; |
| 16 |
char const* const constMsg2 = "hello"; |
| 17 |
char const constMsg3[] = "hello"; |
| 18 |
|
| 19 |
template <const char * const category, const char * const reason> |
| 20 |
void f(const char * arg) { |
| 21 |
__builtin_verbose_trap("cat1", "Arbitrary string literals can be used!"); |
| 22 |
__builtin_verbose_trap(" cat1 ", "Argument_must_not_be_null"); |
| 23 |
__builtin_verbose_trap("cat" "egory1", "hello" "world"); |
| 24 |
__builtin_verbose_trap(constCat1, constMsg1); |
| 25 |
__builtin_verbose_trap(constCat2, constMsg2); |
| 26 |
__builtin_verbose_trap("", ""); |
| 27 |
__builtin_verbose_trap(); // expected-error {{too few arguments}} |
| 28 |
__builtin_verbose_trap(""); // expected-error {{too few arguments}} |
| 29 |
__builtin_verbose_trap("", "", ""); // expected-error {{too many arguments}} |
| 30 |
__builtin_verbose_trap("", 0); // expected-error {{argument to __builtin_verbose_trap must be a pointer to a constant string}} |
| 31 |
__builtin_verbose_trap(1, ""); // expected-error {{cannot initialize a parameter of type 'const char *' with an rvalue of type 'int'}} |
| 32 |
__builtin_verbose_trap(arg, ""); // expected-error {{argument to __builtin_verbose_trap must be a pointer to a constant string}} |
| 33 |
__builtin_verbose_trap("cat$1", "hel$lo"); // expected-error 2 {{argument to __builtin_verbose_trap must not contain $}} |
| 34 |
__builtin_verbose_trap(category, reason); |
| 35 |
__builtin_verbose_trap(u8"cat1", u8"hello"); |
| 36 |
#if __cplusplus >= 202002L |
| 37 |
// FIXME: Accept c++20 u8 string literals. |
| 38 |
// expected-error@-3 {{cannot initialize a parameter of type 'const char *' with an lvalue of type 'const char8_t[5]'}} |
| 39 |
#endif |
| 40 |
__builtin_verbose_trap("", "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd"); |
| 41 |
} |
| 42 |
|
| 43 |
template <const char * const category> |
| 44 |
void f2() { |
| 45 |
__builtin_verbose_trap(category, 1); // expected-error {{cannot initialize a parameter of type 'const char *' with an rvalue of type 'int'}} |
| 46 |
} |
| 47 |
|
| 48 |
void test() { |
| 49 |
f<constCat3, constMsg3>(nullptr); |
| 50 |
} |
| 51 |
|
| 52 |
/// Arguments must be null terminated. |
| 53 |
int foo() { |
| 54 |
constexpr char K[] = {'a', 'b'}; |
| 55 |
__builtin_verbose_trap("hehe", K); // expected-error {{argument to __builtin_verbose_trap must be a pointer to a constant string}} |
| 56 |
__builtin_verbose_trap(K, "hehe"); //expected-error {{argument to __builtin_verbose_trap must be a pointer to a constant string}} |
| 57 |
|
| 58 |
constexpr char K2[] = {'a', 'b', '\0'}; |
| 59 |
__builtin_verbose_trap("hehe", K2); |
| 60 |
__builtin_verbose_trap(K2, "hehe"); |
| 61 |
} |