1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s -fcxx-exceptions -triple=x86_64-linux-gnu
2 // RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s -fcxx-exceptions -triple=x86_64-linux-gnu
4 using size_t = decltype(sizeof(int));
6 int &operator "" _x1 (const char *);
7 double &operator "" _x1 (const char *, size_t);
9 #if __cplusplus >= 202002L
11 float &operator "" _x1 (const char8_t
*, size_t);
15 char8
&i2
= u8
"foo"_x1
;
16 double &i3
= L
"foo"_x1
; // expected-error {{no matching literal operator for call to 'operator""_x1' with arguments of types 'const wchar_t *' and 'unsigned long'}}
18 char &operator "" _x1(const wchar_t *, size_t);
19 char &i4
= L
"foo"_x1
; // ok
20 double &i5
= R
"(foo)"_x1
; // ok
29 #if __cplusplus >= 202002L
30 template<int N
> struct S
{
32 constexpr S(const char (&r
)[N
]) {
33 __builtin_memcpy(a
, r
, N
);
34 if (a
[0] == 'x') throw "no";
37 if (a
[0] == 'y') throw "also no";
41 // Check the produced contents are correct.
42 template<S s
> constexpr const decltype(s
) &operator""_str() { return s
; }
43 static_assert(__builtin_strcmp("hello world"_str
.a
, "hello world") == 0);
45 template<S
> float &operator""_s();
48 // FIXME: It'd be useful to explain what candidates were found and why they didn't work.
49 "xyzzy"_s
; // expected-error {{no matching literal operator for call to 'operator""_s' with arguments of types 'const char *' and 'unsigned long', and no matching literal operator template}}
50 "yello"_s
; // expected-error {{no matching literal operator for call to 'operator""_s' with arguments of types 'const char *' and 'unsigned long', and no matching literal operator template}}
53 double &operator""_s(const char*, size_t);
60 template<S
<4>> float &operator""_t();
61 double &operator""_t(const char*, size_t);
68 template<int N
> struct X
{
69 static constexpr int size
= N
;
70 constexpr X(const char (&r
)[N
]) {}
72 template<X x
> requires (x
.size
== 4) // expected-note {{because 'X<5>{}.size == 4' (5 == 4) evaluated to false}}
73 void operator""_x(); // expected-note {{constraints not satisfied}}
74 void operator""_x(const char*, size_t) = delete;
76 template<int N
> requires (N
== 4)
78 constexpr Y(const char (&r
)[N
]) {}
80 template<Y
> float &operator""_y();
81 void operator""_y(const char*, size_t) = delete; // expected-note {{deleted here}}
87 // We only check the template argument itself for validity, not the whole
88 // call, when deciding whether to use the template or non-template form.
89 "fooo"_x
; // expected-error {{no matching function}}
90 "fooo"_y
; // expected-error {{deleted function}}