19265f7c4SCorentin Jabot // RUN: %clang_cc1 -std=c++2c -triple=x86_64-linux -fsyntax-only %s -verify
247ccfd7aSCorentin Jabot
347ccfd7aSCorentin Jabot static_assert(true, "");
447ccfd7aSCorentin Jabot 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}}
547ccfd7aSCorentin Jabot struct Empty{};
647ccfd7aSCorentin Jabot static_assert(true, Empty{}); // expected-error {{the message object in this static assertion is missing 'data()' and 'size()' member functions}}
747ccfd7aSCorentin Jabot struct NoData {
847ccfd7aSCorentin Jabot unsigned long size() const;
947ccfd7aSCorentin Jabot };
1047ccfd7aSCorentin Jabot struct NoSize {
1147ccfd7aSCorentin Jabot const char* data() const;
1247ccfd7aSCorentin Jabot };
1347ccfd7aSCorentin Jabot static_assert(true, NoData{}); // expected-error {{the message object in this static assertion is missing a 'data()' member function}}
1447ccfd7aSCorentin Jabot static_assert(true, NoSize{}); // expected-error {{the message object in this static assertion is missing a 'size()' member function}}
1547ccfd7aSCorentin Jabot
1647ccfd7aSCorentin Jabot struct InvalidSize {
1747ccfd7aSCorentin Jabot const char* size() const;
1847ccfd7aSCorentin Jabot const char* data() const;
1947ccfd7aSCorentin Jabot };
2047ccfd7aSCorentin Jabot static_assert(true, InvalidSize{}); // expected-error {{the message in a static assertion must have a 'size()' member function returning an object convertible to 'std::size_t'}} \
2147ccfd7aSCorentin Jabot // expected-error {{value of type 'const char *' is not implicitly convertible to 'unsigned long'}}
2247ccfd7aSCorentin Jabot struct InvalidData {
2347ccfd7aSCorentin Jabot unsigned long size() const;
2447ccfd7aSCorentin Jabot unsigned long data() const;
2547ccfd7aSCorentin Jabot };
2647ccfd7aSCorentin Jabot static_assert(true, InvalidData{}); // expected-error {{the message in a static assertion must have a 'data()' member function returning an object convertible to 'const char *'}} \
2747ccfd7aSCorentin Jabot // expected-error {{value of type 'unsigned long' is not implicitly convertible to 'const char *'}}
2847ccfd7aSCorentin Jabot
2947ccfd7aSCorentin Jabot struct NonConstexprSize {
3047ccfd7aSCorentin Jabot unsigned long size() const; // expected-note 2{{declared here}}
3147ccfd7aSCorentin Jabot constexpr const char* data() const;
3247ccfd7aSCorentin Jabot };
3347ccfd7aSCorentin Jabot
3447ccfd7aSCorentin Jabot static_assert(true, NonConstexprSize{}); // expected-error {{the message in this static assertion is not a constant expression}} \
3547ccfd7aSCorentin Jabot // expected-note {{non-constexpr function 'size' cannot be used in a constant expression}}
3647ccfd7aSCorentin Jabot
3747ccfd7aSCorentin Jabot static_assert(false, NonConstexprSize{}); // expected-error {{the message in a static assertion must be produced by a constant expression}} \
3847ccfd7aSCorentin Jabot // expected-error {{static assertion failed}} \
3947ccfd7aSCorentin Jabot // expected-note {{non-constexpr function 'size' cannot be used in a constant expression}}
4047ccfd7aSCorentin Jabot
4147ccfd7aSCorentin Jabot struct NonConstexprData {
sizeNonConstexprData4247ccfd7aSCorentin Jabot constexpr unsigned long size() const {
4347ccfd7aSCorentin Jabot return 32;
4447ccfd7aSCorentin Jabot }
4547ccfd7aSCorentin Jabot const char* data() const; // expected-note 2{{declared here}}
4647ccfd7aSCorentin Jabot };
4747ccfd7aSCorentin Jabot
4847ccfd7aSCorentin Jabot static_assert(true, NonConstexprData{}); // expected-error {{the message in this static assertion is not a constant expression}} \
4947ccfd7aSCorentin Jabot // expected-note {{non-constexpr function 'data' cannot be used in a constant expression}}
5047ccfd7aSCorentin Jabot
5147ccfd7aSCorentin Jabot static_assert(false, NonConstexprData{}); // expected-error {{the message in a static assertion must be produced by a constant expression}} \
5247ccfd7aSCorentin Jabot // expected-error {{static assertion failed}} \
5347ccfd7aSCorentin Jabot // expected-note {{non-constexpr function 'data' cannot be used in a constant expression}}
5447ccfd7aSCorentin Jabot
5547ccfd7aSCorentin Jabot struct string_view {
5647ccfd7aSCorentin Jabot int S;
5747ccfd7aSCorentin Jabot const char* D;
string_viewstring_view5847ccfd7aSCorentin Jabot constexpr string_view(const char* Str) : S(__builtin_strlen(Str)), D(Str) {}
string_viewstring_view5947ccfd7aSCorentin Jabot constexpr string_view(int Size, const char* Str) : S(Size), D(Str) {}
sizestring_view6047ccfd7aSCorentin Jabot constexpr int size() const {
6147ccfd7aSCorentin Jabot return S;
6247ccfd7aSCorentin Jabot }
datastring_view6347ccfd7aSCorentin Jabot constexpr const char* data() const {
6447ccfd7aSCorentin Jabot return D;
6547ccfd7aSCorentin Jabot }
6647ccfd7aSCorentin Jabot };
6747ccfd7aSCorentin Jabot
operator +(auto,string_view S)684d494e76SCorentin Jabot constexpr string_view operator+(auto, string_view S) {
694d494e76SCorentin Jabot return S;
704d494e76SCorentin Jabot }
714d494e76SCorentin Jabot
7247ccfd7aSCorentin Jabot constexpr const char g_[] = "long string";
7347ccfd7aSCorentin Jabot
7447ccfd7aSCorentin Jabot template <typename T, int S>
7547ccfd7aSCorentin Jabot struct array {
sizearray7647ccfd7aSCorentin Jabot constexpr unsigned long size() const {
7747ccfd7aSCorentin Jabot return S;
7847ccfd7aSCorentin Jabot }
dataarray7947ccfd7aSCorentin Jabot constexpr const char* data() const {
8047ccfd7aSCorentin Jabot return d_;
8147ccfd7aSCorentin Jabot }
8247ccfd7aSCorentin Jabot const char d_[S];
8347ccfd7aSCorentin Jabot };
8447ccfd7aSCorentin Jabot
8547ccfd7aSCorentin Jabot static_assert(false, string_view("test")); // expected-error {{static assertion failed: test}}
864d494e76SCorentin Jabot static_assert(false, "Literal" + string_view("test")); // expected-error {{static assertion failed: test}}
874d494e76SCorentin Jabot static_assert(false, L"Wide Literal" + string_view("test")); // expected-error {{static assertion failed: test}}
884d494e76SCorentin Jabot static_assert(false, "Wild" "Literal" "Concatenation" + string_view("test")); // expected-error {{static assertion failed: test}}
894d494e76SCorentin Jabot static_assert(false, "Wild" "Literal" L"Concatenation" + string_view("test")); // expected-error {{static assertion failed: test}}
904d494e76SCorentin Jabot static_assert(false, "Wild" u"Literal" L"Concatenation" + string_view("test")); // expected-error {{unsupported non-standard concatenation of string literals}}
9147ccfd7aSCorentin Jabot static_assert(false, string_view("")); // expected-error {{static assertion failed: }}
9247ccfd7aSCorentin Jabot static_assert(false, string_view(0, nullptr)); // expected-error {{static assertion failed:}}
9347ccfd7aSCorentin Jabot static_assert(false, string_view(1, "ABC")); // expected-error {{static assertion failed: A}}
9447ccfd7aSCorentin Jabot static_assert(false, string_view(42, "ABC")); // expected-error {{static assertion failed: ABC}} \
9547ccfd7aSCorentin Jabot // expected-error {{the message in a static assertion must be produced by a constant expression}} \
9647ccfd7aSCorentin Jabot // expected-note {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
9747ccfd7aSCorentin Jabot static_assert(false, array<char, 2>{'a', 'b'}); // expected-error {{static assertion failed: ab}}
9847ccfd7aSCorentin Jabot
9947ccfd7aSCorentin Jabot
10047ccfd7aSCorentin Jabot
10147ccfd7aSCorentin Jabot struct ConvertibleToInt {
operator intConvertibleToInt10247ccfd7aSCorentin Jabot constexpr operator int() {
10347ccfd7aSCorentin Jabot return 4;
10447ccfd7aSCorentin Jabot }
10547ccfd7aSCorentin Jabot };
10647ccfd7aSCorentin Jabot struct ConvertibleToCharPtr {
operator const char*ConvertibleToCharPtr10747ccfd7aSCorentin Jabot constexpr operator const char*() {
10847ccfd7aSCorentin Jabot return "test";
10947ccfd7aSCorentin Jabot }
11047ccfd7aSCorentin Jabot };
11147ccfd7aSCorentin Jabot struct MessageFromConvertible {
sizeMessageFromConvertible11247ccfd7aSCorentin Jabot constexpr ConvertibleToInt size() const {
11347ccfd7aSCorentin Jabot return {};
11447ccfd7aSCorentin Jabot }
dataMessageFromConvertible11547ccfd7aSCorentin Jabot constexpr ConvertibleToCharPtr data() const {
11647ccfd7aSCorentin Jabot return {};
11747ccfd7aSCorentin Jabot }
11847ccfd7aSCorentin Jabot };
11947ccfd7aSCorentin Jabot
12047ccfd7aSCorentin Jabot static_assert(true, MessageFromConvertible{});
12147ccfd7aSCorentin Jabot static_assert(false, MessageFromConvertible{}); // expected-error{{static assertion failed: test}}
12247ccfd7aSCorentin Jabot
12347ccfd7aSCorentin Jabot
12447ccfd7aSCorentin Jabot
12547ccfd7aSCorentin Jabot struct Leaks {
sizeLeaks12647ccfd7aSCorentin Jabot constexpr unsigned long size() const {
12747ccfd7aSCorentin Jabot return 2;
12847ccfd7aSCorentin Jabot }
dataLeaks12947ccfd7aSCorentin Jabot constexpr const char* data() const {
13047ccfd7aSCorentin Jabot return new char[2]{'u', 'b'}; // expected-note {{allocation performed here was not deallocated}}
13147ccfd7aSCorentin Jabot }
13247ccfd7aSCorentin Jabot };
13347ccfd7aSCorentin Jabot
13447ccfd7aSCorentin Jabot static_assert(false, Leaks{}); //expected-error {{the message in a static assertion must be produced by a constant expression}} \
13547ccfd7aSCorentin Jabot // expected-error {{static assertion failed: ub}}
13647ccfd7aSCorentin Jabot
13747ccfd7aSCorentin Jabot struct RAII {
__anon553797ed0202RAII13847ccfd7aSCorentin Jabot const char* d = new char[2]{'o', 'k'};
sizeRAII13947ccfd7aSCorentin Jabot constexpr unsigned long size() const {
14047ccfd7aSCorentin Jabot return 2;
14147ccfd7aSCorentin Jabot }
14247ccfd7aSCorentin Jabot
dataRAII14347ccfd7aSCorentin Jabot constexpr const char* data() const {
14447ccfd7aSCorentin Jabot return d;
14547ccfd7aSCorentin Jabot }
14647ccfd7aSCorentin Jabot
~RAIIRAII14747ccfd7aSCorentin Jabot constexpr ~RAII() {
14847ccfd7aSCorentin Jabot delete[] d;
14947ccfd7aSCorentin Jabot }
15047ccfd7aSCorentin Jabot };
15147ccfd7aSCorentin Jabot static_assert(false, RAII{}); // expected-error {{static assertion failed: ok}}
15247ccfd7aSCorentin Jabot
15347ccfd7aSCorentin Jabot namespace MoreTemporary {
15447ccfd7aSCorentin Jabot
15547ccfd7aSCorentin Jabot struct Data{
operator const char*MoreTemporary::Data15647ccfd7aSCorentin Jabot constexpr operator const char*() const {
15747ccfd7aSCorentin Jabot return d;
15847ccfd7aSCorentin Jabot }
15947ccfd7aSCorentin Jabot char d[6] = { "Hello" };
16047ccfd7aSCorentin Jabot };
16147ccfd7aSCorentin Jabot
16247ccfd7aSCorentin Jabot struct Size {
operator intMoreTemporary::Size16347ccfd7aSCorentin Jabot constexpr operator int() const {
16447ccfd7aSCorentin Jabot return 5;
16547ccfd7aSCorentin Jabot }
16647ccfd7aSCorentin Jabot };
16747ccfd7aSCorentin Jabot
16847ccfd7aSCorentin Jabot struct Message {
sizeMoreTemporary::Message16947ccfd7aSCorentin Jabot constexpr auto size() const {
17047ccfd7aSCorentin Jabot return Size{};
17147ccfd7aSCorentin Jabot }
dataMoreTemporary::Message17247ccfd7aSCorentin Jabot constexpr auto data() const {
17347ccfd7aSCorentin Jabot return Data{};
17447ccfd7aSCorentin Jabot }
17547ccfd7aSCorentin Jabot };
17647ccfd7aSCorentin Jabot
17747ccfd7aSCorentin Jabot static_assert(false, Message{}); // expected-error {{static assertion failed: Hello}}
17847ccfd7aSCorentin Jabot
17947ccfd7aSCorentin Jabot }
18047ccfd7aSCorentin Jabot
18147ccfd7aSCorentin Jabot struct MessageInvalidSize {
182fdefe88bScor3ntin constexpr unsigned long size(int) const; // expected-note {{'size' declared here}}
183fdefe88bScor3ntin constexpr const char* data() const;
18447ccfd7aSCorentin Jabot };
18547ccfd7aSCorentin Jabot struct MessageInvalidData {
186fdefe88bScor3ntin constexpr unsigned long size() const;
187fdefe88bScor3ntin constexpr const char* data(int) const; // expected-note {{'data' declared here}}
18847ccfd7aSCorentin Jabot };
18947ccfd7aSCorentin Jabot
19047ccfd7aSCorentin Jabot static_assert(false, MessageInvalidSize{}); // expected-error {{static assertion failed}} \
191fdefe88bScor3ntin // expected-error {{the message in a static assertion must have a 'size()' member function returning an object convertible to 'std::size_t'}} \
192fdefe88bScor3ntin // expected-error {{too few arguments to function call, expected 1, have 0}}
19347ccfd7aSCorentin Jabot static_assert(false, MessageInvalidData{}); // expected-error {{static assertion failed}} \
194fdefe88bScor3ntin // expected-error {{the message in a static assertion must have a 'data()' member function returning an object convertible to 'const char *'}} \
195fdefe88bScor3ntin // expected-error {{too few arguments to function call, expected 1, have 0}}
19647ccfd7aSCorentin Jabot
19747ccfd7aSCorentin Jabot struct NonConstMembers {
sizeNonConstMembers19847ccfd7aSCorentin Jabot constexpr int size() {
19947ccfd7aSCorentin Jabot return 1;
20047ccfd7aSCorentin Jabot }
dataNonConstMembers20147ccfd7aSCorentin Jabot constexpr const char* data() {
20247ccfd7aSCorentin Jabot return "A";
20347ccfd7aSCorentin Jabot }
20447ccfd7aSCorentin Jabot };
20547ccfd7aSCorentin Jabot
20647ccfd7aSCorentin Jabot static_assert(false, NonConstMembers{}); // expected-error {{static assertion failed: A}}
20747ccfd7aSCorentin Jabot
20847ccfd7aSCorentin Jabot struct DefaultArgs {
sizeDefaultArgs20947ccfd7aSCorentin Jabot constexpr int size(int i = 0) {
21047ccfd7aSCorentin Jabot return 2;
21147ccfd7aSCorentin Jabot }
dataDefaultArgs21247ccfd7aSCorentin Jabot constexpr const char* data(int i =0, int j = 42) {
21347ccfd7aSCorentin Jabot return "OK";
21447ccfd7aSCorentin Jabot }
21547ccfd7aSCorentin Jabot };
21647ccfd7aSCorentin Jabot
21747ccfd7aSCorentin Jabot static_assert(false, DefaultArgs{}); // expected-error {{static assertion failed: OK}}
21847ccfd7aSCorentin Jabot
21947ccfd7aSCorentin Jabot struct Variadic {
sizeVariadic22047ccfd7aSCorentin Jabot constexpr int size(auto...) {
22147ccfd7aSCorentin Jabot return 2;
22247ccfd7aSCorentin Jabot }
dataVariadic22347ccfd7aSCorentin Jabot constexpr const char* data(auto...) {
22447ccfd7aSCorentin Jabot return "OK";
22547ccfd7aSCorentin Jabot }
22647ccfd7aSCorentin Jabot };
22747ccfd7aSCorentin Jabot
22847ccfd7aSCorentin Jabot static_assert(false, Variadic{}); // expected-error {{static assertion failed: OK}}
22947ccfd7aSCorentin Jabot
23047ccfd7aSCorentin Jabot template <typename T>
23147ccfd7aSCorentin Jabot struct DeleteAndRequires {
232fdefe88bScor3ntin constexpr int size() = delete; // expected-note {{'size' has been explicitly marked deleted here}}
233fdefe88bScor3ntin constexpr const char* data() requires false; // expected-note {{because 'false' evaluated to false}}
23447ccfd7aSCorentin Jabot };
23547ccfd7aSCorentin Jabot static_assert(false, DeleteAndRequires<void>{});
23647ccfd7aSCorentin Jabot // expected-error@-1 {{static assertion failed}} \
23747ccfd7aSCorentin Jabot // expected-error@-1 {{the message in a static assertion must have a 'size()' member function returning an object convertible to 'std::size_t'}}\
238fdefe88bScor3ntin // expected-error@-1 {{invalid reference to function 'data': constraints not satisfied}} \
239fdefe88bScor3ntin // expected-error@-1 {{attempt to use a deleted function}}
24047ccfd7aSCorentin Jabot
24147ccfd7aSCorentin Jabot class Private {
size(int i=0)24247ccfd7aSCorentin Jabot constexpr int size(int i = 0) { // expected-note {{implicitly declared private here}}
24347ccfd7aSCorentin Jabot return 2;
24447ccfd7aSCorentin Jabot }
data(int i=0,int j=42)24547ccfd7aSCorentin Jabot constexpr const char* data(int i =0, int j = 42) { // expected-note {{implicitly declared private here}}
24647ccfd7aSCorentin Jabot return "OK";
24747ccfd7aSCorentin Jabot }
24847ccfd7aSCorentin Jabot };
24947ccfd7aSCorentin Jabot
25047ccfd7aSCorentin Jabot static_assert(false, Private{}); // expected-error {{'data' is a private member of 'Private'}}\
25147ccfd7aSCorentin Jabot // expected-error {{'size' is a private member of 'Private'}}\
25247ccfd7aSCorentin Jabot // expected-error {{static assertion failed: OK}}
25347ccfd7aSCorentin Jabot
25447ccfd7aSCorentin Jabot struct MessageOverload {
sizeMessageOverload25547ccfd7aSCorentin Jabot constexpr int size() {
25647ccfd7aSCorentin Jabot return 1;
25747ccfd7aSCorentin Jabot }
25847ccfd7aSCorentin Jabot constexpr int size() const;
25947ccfd7aSCorentin Jabot
dataMessageOverload26047ccfd7aSCorentin Jabot constexpr const char* data() {
26147ccfd7aSCorentin Jabot return "A";
26247ccfd7aSCorentin Jabot }
26347ccfd7aSCorentin Jabot constexpr const char* data() const;
26447ccfd7aSCorentin Jabot };
26547ccfd7aSCorentin Jabot
26647ccfd7aSCorentin Jabot static_assert(false, MessageOverload{}); // expected-error {{static assertion failed: A}}
26747ccfd7aSCorentin Jabot
26847ccfd7aSCorentin Jabot struct InvalidPtr {
sizeInvalidPtr26947ccfd7aSCorentin Jabot consteval auto size() {
27047ccfd7aSCorentin Jabot return 42;
27147ccfd7aSCorentin Jabot }
dataInvalidPtr27247ccfd7aSCorentin Jabot consteval const char *data() {
27347ccfd7aSCorentin Jabot const char *ptr; // Garbage
27447ccfd7aSCorentin Jabot return ptr; // expected-note {{read of uninitialized object is not allowed in a constant expression}}
27547ccfd7aSCorentin Jabot }
27647ccfd7aSCorentin Jabot };
27747ccfd7aSCorentin Jabot
27847ccfd7aSCorentin Jabot static_assert(false, InvalidPtr{}); // expected-error{{the message in a static assertion must be produced by a constant expression}} \
27947ccfd7aSCorentin Jabot //expected-error {{static assertion failed}} \
28047ccfd7aSCorentin Jabot // expected-note {{in call to 'InvalidPtr{}.data()'}}
28147ccfd7aSCorentin Jabot
28247ccfd7aSCorentin Jabot namespace DependentMessage {
28347ccfd7aSCorentin Jabot template <typename Ty>
28447ccfd7aSCorentin Jabot struct Good {
28547ccfd7aSCorentin Jabot static_assert(false, Ty{}); // expected-error {{static assertion failed: hello}}
28647ccfd7aSCorentin Jabot };
28747ccfd7aSCorentin Jabot
28847ccfd7aSCorentin Jabot template <typename Ty>
28947ccfd7aSCorentin Jabot struct Bad {
29047ccfd7aSCorentin Jabot 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}} \
29147ccfd7aSCorentin Jabot // expected-error {{static assertion failed}}
29247ccfd7aSCorentin Jabot };
29347ccfd7aSCorentin Jabot
29447ccfd7aSCorentin Jabot struct Frobble {
sizeDependentMessage::Frobble29547ccfd7aSCorentin Jabot constexpr int size() const { return 5; }
dataDependentMessage::Frobble29647ccfd7aSCorentin Jabot constexpr const char *data() const { return "hello"; }
29747ccfd7aSCorentin Jabot };
29847ccfd7aSCorentin Jabot
operator ""_myd(const char *,unsigned long)299fdefe88bScor3ntin constexpr Frobble operator ""_myd (const char *, unsigned long) { return Frobble{}; }
300fdefe88bScor3ntin static_assert (false, "foo"_myd); // expected-error {{static assertion failed: hello}}
301fdefe88bScor3ntin
30247ccfd7aSCorentin Jabot Good<Frobble> a; // expected-note {{in instantiation}}
30347ccfd7aSCorentin Jabot Bad<int> b; // expected-note {{in instantiation}}
30447ccfd7aSCorentin Jabot
30547ccfd7aSCorentin Jabot }
3062176c5e5STakuya Shimizu
3072176c5e5STakuya Shimizu namespace EscapeInDiagnostic {
3082176c5e5STakuya Shimizu static_assert('\u{9}' == (char)1, ""); // expected-error {{failed}} \
3092176c5e5STakuya Shimizu // expected-note {{evaluates to ''\t' (0x09, 9) == '<U+0001>' (0x01, 1)'}}
3102176c5e5STakuya Shimizu static_assert((char8_t)-128 == (char8_t)-123, ""); // expected-error {{failed}} \
3112176c5e5STakuya Shimizu // expected-note {{evaluates to 'u8'<80>' (0x80, 128) == u8'<85>' (0x85, 133)'}}
3122176c5e5STakuya Shimizu static_assert((char16_t)0xFEFF == (char16_t)0xDB93, ""); // expected-error {{failed}} \
3132176c5e5STakuya Shimizu // expected-note {{evaluates to 'u'' (0xFEFF, 65279) == u'\xDB93' (0xDB93, 56211)'}}
3142176c5e5STakuya Shimizu }
315fdefe88bScor3ntin
316fdefe88bScor3ntin struct Static {
sizeStatic317fdefe88bScor3ntin static constexpr int size() { return 5; }
dataStatic318fdefe88bScor3ntin static constexpr const char *data() { return "hello"; }
319fdefe88bScor3ntin };
320fdefe88bScor3ntin static_assert(false, Static{}); // expected-error {{static assertion failed: hello}}
321fdefe88bScor3ntin
322fdefe88bScor3ntin struct Data {
323fdefe88bScor3ntin unsigned long size = 0;
324fdefe88bScor3ntin const char* data = "hello";
325fdefe88bScor3ntin };
326fdefe88bScor3ntin static_assert(false, Data{}); // expected-error {{called object type 'unsigned long' is not a function or function pointer}} \
327fdefe88bScor3ntin // expected-error {{called object type 'const char *' is not a function or function pointer}} \
328fdefe88bScor3ntin // expected-error {{the message in a static assertion must have a 'size()' member function returning an object convertible to 'std::size_t'}} \
329fdefe88bScor3ntin // expected-error {{static assertion failed}}
330fdefe88bScor3ntin
331fdefe88bScor3ntin struct Callable {
332fdefe88bScor3ntin struct {
operator ()Callable::__anon553797ed0308333fdefe88bScor3ntin constexpr auto operator()() const {
334fdefe88bScor3ntin return 5;
335fdefe88bScor3ntin };
336fdefe88bScor3ntin } size;
337fdefe88bScor3ntin struct {
operator ()Callable::__anon553797ed0408338fdefe88bScor3ntin constexpr auto operator()() const {
339fdefe88bScor3ntin return "hello";
340fdefe88bScor3ntin };
341fdefe88bScor3ntin } data;
342fdefe88bScor3ntin };
343fdefe88bScor3ntin static_assert(false, Callable{}); // expected-error {{static assertion failed: hello}}
344*b6628c24SSirraide
345*b6628c24SSirraide namespace GH89407 {
346*b6628c24SSirraide struct A {
sizeGH89407::A347*b6628c24SSirraide constexpr __SIZE_TYPE__ size() const { return -1; }
dataGH89407::A348*b6628c24SSirraide constexpr const char* data() const { return ""; }
349*b6628c24SSirraide };
350*b6628c24SSirraide
351*b6628c24SSirraide struct B {
sizeGH89407::B352*b6628c24SSirraide constexpr long long size() const { return 18446744073709551615U; }
dataGH89407::B353*b6628c24SSirraide constexpr const char* data() const { return ""; }
354*b6628c24SSirraide };
355*b6628c24SSirraide
356*b6628c24SSirraide struct C {
sizeGH89407::C357*b6628c24SSirraide constexpr __int128 size() const { return -1; }
dataGH89407::C358*b6628c24SSirraide constexpr const char* data() const { return ""; }
359*b6628c24SSirraide };
360*b6628c24SSirraide
361*b6628c24SSirraide struct D {
sizeGH89407::D362*b6628c24SSirraide constexpr unsigned __int128 size() const { return -1; }
dataGH89407::D363*b6628c24SSirraide constexpr const char* data() const { return ""; }
364*b6628c24SSirraide };
365*b6628c24SSirraide
366*b6628c24SSirraide struct E {
sizeGH89407::E367*b6628c24SSirraide constexpr __SIZE_TYPE__ size() const { return 18446744073709551615U; }
dataGH89407::E368*b6628c24SSirraide constexpr const char* data() const { return ""; }
369*b6628c24SSirraide };
370*b6628c24SSirraide
371*b6628c24SSirraide static_assert(true, A{}); // expected-error {{the message in this static assertion is not a constant expression}}
372*b6628c24SSirraide // expected-note@-1 {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
373*b6628c24SSirraide static_assert(true, B{}); // expected-error {{call to 'size()' evaluates to -1, which cannot be narrowed to type 'unsigned long'}}
374*b6628c24SSirraide // expected-error@-1 {{the message in this static assertion is not a constant expression}}
375*b6628c24SSirraide // expected-note@-2 {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
376*b6628c24SSirraide static_assert(true, C{}); // expected-error {{call to 'size()' evaluates to -1, which cannot be narrowed to type 'unsigned long'}}
377*b6628c24SSirraide // expected-error@-1 {{the message in this static assertion is not a constant expression}}
378*b6628c24SSirraide // expected-note@-2 {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
379*b6628c24SSirraide static_assert(true, D{}); // expected-error {{call to 'size()' evaluates to 340282366920938463463374607431768211455, which cannot be narrowed to type 'unsigned long'}}
380*b6628c24SSirraide // expected-error@-1 {{the message in this static assertion is not a constant expression}}
381*b6628c24SSirraide // expected-note@-2 {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
382*b6628c24SSirraide static_assert(true, E{}); // expected-error {{the message in this static assertion is not a constant expression}}
383*b6628c24SSirraide // expected-note@-1 {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
384*b6628c24SSirraide
385*b6628c24SSirraide static_assert(
386*b6628c24SSirraide false, // expected-error {{static assertion failed}}
387*b6628c24SSirraide A{} // expected-error {{the message in a static assertion must be produced by a constant expression}}
388*b6628c24SSirraide // expected-note@-1 {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
389*b6628c24SSirraide );
390*b6628c24SSirraide
391*b6628c24SSirraide static_assert(
392*b6628c24SSirraide false, // expected-error {{static assertion failed}}
393*b6628c24SSirraide B{} // expected-error {{call to 'size()' evaluates to -1, which cannot be narrowed to type 'unsigned long'}}
394*b6628c24SSirraide // expected-error@-1 {{the message in a static assertion must be produced by a constant expression}}
395*b6628c24SSirraide // expected-note@-2 {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
396*b6628c24SSirraide );
397*b6628c24SSirraide
398*b6628c24SSirraide static_assert(
399*b6628c24SSirraide false, // expected-error {{static assertion failed}}
400*b6628c24SSirraide C{} // expected-error {{call to 'size()' evaluates to -1, which cannot be narrowed to type 'unsigned long'}}
401*b6628c24SSirraide // expected-error@-1 {{the message in a static assertion must be produced by a constant expression}}
402*b6628c24SSirraide // expected-note@-2 {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
403*b6628c24SSirraide );
404*b6628c24SSirraide
405*b6628c24SSirraide static_assert(
406*b6628c24SSirraide false, // expected-error {{static assertion failed}}
407*b6628c24SSirraide D{} // expected-error {{call to 'size()' evaluates to 340282366920938463463374607431768211455, which cannot be narrowed to type 'unsigned long'}}
408*b6628c24SSirraide // expected-error@-1 {{the message in a static assertion must be produced by a constant expression}}
409*b6628c24SSirraide // expected-note@-2 {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
410*b6628c24SSirraide );
411*b6628c24SSirraide
412*b6628c24SSirraide static_assert(
413*b6628c24SSirraide false, // expected-error {{static assertion failed}}
414*b6628c24SSirraide E{} // expected-error {{the message in a static assertion must be produced by a constant expression}}
415*b6628c24SSirraide // expected-note@-1 {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
416*b6628c24SSirraide );
417*b6628c24SSirraide }
418