62 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify %s2// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify %s3 4// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify %s -fexperimental-new-constant-interpreter5// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify %s -fexperimental-new-constant-interpreter6 7#if !__has_builtin(__builtin_verbose_trap)8#error9#endif10 11constexpr char const* constCat1 = "cat";12char const* const constCat2 = "cat";13char const constCat3[] = "cat";14 15constexpr char const* constMsg1 = "hello";16char const* const constMsg2 = "hello";17char const constMsg3[] = "hello";18 19template <const char * const category, const char * const reason>20void 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 >= 202002L37 // 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#endif40 __builtin_verbose_trap("", "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd");41}42 43template <const char * const category>44void 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 48void test() {49 f<constCat3, constMsg3>(nullptr);50}51 52/// Arguments must be null terminated.53int 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}62