Debian Codegraph @

gcc/testsuite/g++.dg/cpp26/unevalstr2.C

raw
1 // C++26 P2361R6 - Unevaluated strings
2 // { dg-do compile { target { c++11 && c++23_down } } }
3 // { dg-options "-pedantic" }
4
5 static_assert (true, "foo");
6 static_assert (true, "foo" " " "bar");
7 static_assert (true, "\u01FC\U000001FC\u{1FC}\N{LATIN CAPITAL LETTER AE WITH ACUTE}\\\'\"\?\a\b\f\n\r\t\v");
8 // { dg-warning "delimited escape sequences are only valid in" "" { target c++20_down } .-1 }
9 // { dg-warning "named universal character escapes are only valid in" "" { target c++20_down } .-2 }
10 static_assert (true, L"foo");
11 static_assert (true, u"foo");
12 static_assert (true, U"foo");
13 static_assert (true, u8"foo");
14 static_assert (true, L"fo" "o");
15 static_assert (true, u"fo" "o");
16 static_assert (true, U"fo" "o");
17 static_assert (true, u8"fo" "o");
18 static_assert (true, "fo" L"o");
19 static_assert (true, "fo" u"o");
20 static_assert (true, "fo" U"o");
21 static_assert (true, "fo" u8"o");
22 static_assert (true, "\0");
23 static_assert (true, "\17");
24 static_assert (true, "\x20");
25 static_assert (true, "\o{17}"); // { dg-warning "delimited escape sequences are only valid in" "" { target c++20_down } }
26 static_assert (true, "\x{20}"); // { dg-warning "delimited escape sequences are only valid in" "" { target c++20_down } }
27 static_assert (true, "\h"); // { dg-warning "unknown escape sequence" }
28
29 extern "C" "+" "+" int f0 ();
30 extern "C" int f1 ();
31 extern "C" { int f2 (); };
32 extern L"C" int f3 (); // { dg-error "a wide string is invalid in this context" }
33 extern L"C" { int f4 (); } // { dg-error "a wide string is invalid in this context" }
34 extern u"C" int f5 (); // { dg-error "a wide string is invalid in this context" }
35 extern u"C" { int f6 (); } // { dg-error "a wide string is invalid in this context" }
36 extern U"C" int f7 (); // { dg-error "a wide string is invalid in this context" }
37 extern U"C" { int f8 (); } // { dg-error "a wide string is invalid in this context" }
38 extern u8"C" int f9 (); // { dg-error "a wide string is invalid in this context" }
39 extern u8"C" { int f10 (); } // { dg-error "a wide string is invalid in this context" }
40 extern "\x43" int f11 ();
41 extern "\x{43}" { int f12 (); } // { dg-warning "delimited escape sequences are only valid in" "" { target c++20_down } }
42 extern "\103" int f13 ();
43 extern "\o{0103}" { int f14 (); } // { dg-warning "delimited escape sequences are only valid in" "" { target c++20_down } }
44
45 [[deprecated ("foo")]] int g0 ();
46 [[deprecated ("foo" " " "bar")]] int g1 ();
47 [[deprecated ("\u01FC\U000001FC\u{1FC}\N{LATIN CAPITAL LETTER AE WITH ACUTE}\\\'\"\?\a\b\f\n\r\t\v")]] int g2 ();
48 // { dg-warning "delimited escape sequences are only valid in" "" { target c++20_down } .-1 }
49 // { dg-warning "named universal character escapes are only valid in" "" { target c++20_down } .-2 }
50 [[deprecated (L"foo")]] int g3 ();
51 [[deprecated (u"foo")]] int g4 ();
52 [[deprecated (U"foo")]] int g5 ();
53 [[deprecated (u8"foo")]] int g6 ();
54 [[deprecated (L"fo" "o")]] int g7 ();
55 [[deprecated (u"fo" "o")]] int g8 ();
56 [[deprecated (U"fo" "o")]] int g9 ();
57 [[deprecated (u8"fo" "o")]] int g10 ();
58 [[deprecated ("fo" L"o")]] int g11 ();
59 [[deprecated ("fo" u"o")]] int g12 ();
60 [[deprecated ("fo" U"o")]] int g13 ();
61 [[deprecated ("fo" u8"o")]] int g14 ();
62 [[deprecated ("\0")]] int g15 ();
63 [[deprecated ("\17")]] int g16 ();
64 [[deprecated ("\x20")]] int g17 ();
65 [[deprecated ("\o{17}")]] int g18 (); // { dg-warning "delimited escape sequences are only valid in" "" { target c++20_down } }
66 [[deprecated ("\x{20}")]] int g19 (); // { dg-warning "delimited escape sequences are only valid in" "" { target c++20_down } }
67 [[deprecated ("\h")]] int g20 (); // { dg-warning "unknown escape sequence" }
68
69 [[nodiscard ("foo")]] int h0 ();
70 [[nodiscard ("foo" " " "bar")]] int h1 ();
71 [[nodiscard ("\u01FC\U000001FC\u{1FC}\N{LATIN CAPITAL LETTER AE WITH ACUTE}\\\'\"\?\a\b\f\n\r\t\v")]] int h2 ();
72 // { dg-warning "delimited escape sequences are only valid in" "" { target c++20_down } .-1 }
73 // { dg-warning "named universal character escapes are only valid in" "" { target c++20_down } .-2 }
74 [[nodiscard (L"foo")]] int h3 ();
75 [[nodiscard (u"foo")]] int h4 ();
76 [[nodiscard (U"foo")]] int h5 ();
77 [[nodiscard (u8"foo")]] int h6 ();
78 [[nodiscard (L"fo" "o")]] int h7 ();
79 [[nodiscard (u"fo" "o")]] int h8 ();
80 [[nodiscard (U"fo" "o")]] int h9 ();
81 [[nodiscard (u8"fo" "o")]] int h10 ();
82 [[nodiscard ("fo" L"o")]] int h11 ();
83 [[nodiscard ("fo" u"o")]] int h12 ();
84 [[nodiscard ("fo" U"o")]] int h13 ();
85 [[nodiscard ("fo" u8"o")]] int h14 ();
86 [[nodiscard ("\0")]] int h15 ();
87 [[nodiscard ("\17")]] int h16 ();
88 [[nodiscard ("\x20")]] int h17 ();
89 [[nodiscard ("\o{17}")]] int h18 (); // { dg-warning "delimited escape sequences are only valid in" "" { target c++20_down } }
90 [[nodiscard ("\x{20}")]] int h19 (); // { dg-warning "delimited escape sequences are only valid in" "" { target c++20_down } }
91 [[nodiscard ("\h")]] int h20 (); // { dg-warning "unknown escape sequence" }
92
93 float operator "" _my0 (const char *);
94 float operator "" "" _my1 (const char *);
95 float operator L"" _my2 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
96 float operator u"" _my3 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
97 float operator U"" _my4 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
98 float operator u8"" _my5 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
99 float operator L"" "" _my6 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
100 float operator u"" "" _my7 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
101 float operator U"" "" _my8 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
102 float operator u8"" "" _my9 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
103 float operator "" L"" _my10 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
104 float operator "" u"" _my11 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
105 float operator "" U"" _my12 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
106 float operator "" u8"" _my13 (const char *); // { dg-error "invalid encoding prefix in literal operator" "" { target c++20 } }
107 float operator "\0" _my14 (const char *); // { dg-error "expected empty string after 'operator' keyword" }
108 float operator "\x00" _my15 (const char *); // { dg-error "expected empty string after 'operator' keyword" }
109 float operator "\h" _my16 (const char *); // { dg-error "expected empty string after 'operator' keyword" }
110 // { dg-warning "unknown escape sequence" "" { target *-*-* } .-1 }
111 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
112 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
113 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
114 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
115 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
116 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
117 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
118 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
119 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
120 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
121 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
122 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
123 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
124 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
125 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
126 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
127 // { dg-warning "space between quotes and suffix is deprecated" "" { target c++23 } .-18 }
128
129 float operator ""_my20 (const char *);
130 float operator "" ""_my21 (const char *);
131 float operator L""_my22 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
132 float operator u""_my23 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
133 float operator U""_my24 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
134 float operator u8""_my25 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
135 float operator L"" ""_my26 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
136 float operator u"" ""_my27 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
137 float operator U"" ""_my28 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
138 float operator u8"" ""_my29 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
139 float operator "" L""_my30 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
140 float operator "" u""_my31 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
141 float operator "" U""_my32 (const char *); // { dg-error "invalid encoding prefix in literal operator" }
142 float operator "" u8""_my33 (const char *); // { dg-error "invalid encoding prefix in literal operator" "" { target c++20 } }
143 float operator "\0"_my34 (const char *); // { dg-error "expected empty string after 'operator' keyword" }
144 float operator "\x00"_my35 (const char *); // { dg-error "expected empty string after 'operator' keyword" }
145 float operator "\h"_my36 (const char *); // { dg-error "expected empty string after 'operator' keyword" }
146 // { dg-warning "unknown escape sequence" "" { target *-*-* } .-1 }