1 // RUN: %clang_cc1 -std=c++11 -verify %s -fms-extensions -triple x86_64-apple-darwin9.0.0
3 // A ud-suffix cannot be used on string literals in a whole bunch of contexts:
5 #include "foo"_bar // expected-error {{expected "FILENAME" or <FILENAME>}}
6 #line 1 "foo"_bar // expected-error {{user-defined suffix cannot be used here}}
7 # 1 "foo"_bar 1 // expected-error {{user-defined suffix cannot be used here}}
8 #ident "foo"_bar // expected-error {{user-defined suffix cannot be used here}}
9 _Pragma("foo"_bar
) // expected-error {{user-defined suffix cannot be used here}}
10 #pragma comment(lib, "foo"_bar) // expected-error {{user-defined suffix cannot be used here}}
11 _Pragma("comment(lib, \"foo\"_bar)") // expected-error {{user-defined suffix cannot be used here}}
12 #pragma message "hi"_there // expected-error {{user-defined suffix cannot be used here}} expected-warning {{hi}}
13 #pragma push_macro("foo"_bar) // expected-error {{user-defined suffix cannot be used here}}
14 #if __has_warning("-Wan-island-to-discover"_bar) // expected-error {{user-defined suffix cannot be used here}}
15 #elif __has_include("foo"_bar) // expected-error {{expected "FILENAME" or <FILENAME>}}
18 extern "C++"_x
{} // expected-error {{user-defined suffix cannot be used here}}
21 asm("mov %eax, %rdx"_foo
); // expected-error {{user-defined suffix cannot be used here}}
24 static_assert(true, "foo"_bar
); // expected-error {{user-defined suffix cannot be used here}}
26 int cake() __attribute__((availability(macosx
, unavailable
, message
= "is a lie"_x
))); // expected-error {{user-defined suffix cannot be used here}}
28 // A ud-suffix cannot be used on character literals in preprocessor constant
30 #if 'x'_y - u'x'_z // expected-error 2{{character literal with user-defined suffix cannot be used in preprocessor constant expression}}
34 // A ud-suffix cannot be used on integer literals in preprocessor constant
36 #if 0_foo // expected-error {{integer literal with user-defined suffix cannot be used in preprocessor constant expression}}
40 // But they can appear in expressions.
41 constexpr char operator"" _id(char c
) { return c
; }
42 constexpr wchar_t operator"" _id(wchar_t c
) { return c
; }
43 constexpr char16_t
operator"" _id(char16_t c
) { return c
; }
44 constexpr char32_t
operator"" _id(char32_t c
) { return c
; }
46 using size_t = decltype(sizeof(int));
47 constexpr const char operator"" _id(const char *p
, size_t n
) { return *p
; }
48 constexpr const wchar_t operator"" _id(const wchar_t *p
, size_t n
) { return *p
; }
49 constexpr const char16_t
operator"" _id(const char16_t
*p
, size_t n
) { return *p
; }
50 constexpr const char32_t
operator"" _id(const char32_t
*p
, size_t n
) { return *p
; }
52 constexpr unsigned long long operator"" _id(unsigned long long n
) { return n
; }
53 constexpr long double operator"" _id(long double d
) { return d
; }
55 template<int n
> struct S
{};
71 (void)"test"_id
"test" L
"test";
74 // Test source location for suffix is known
80 _no_such_suffix
// expected-error {{'operator""_no_such_suffix'}}
82 "and another suffix"_no_such_suffix
;
86 _no_such_suffix
; // expected-error {{'operator""_no_such_suffix'}}
90 _no_such_suffix
; // expected-error {{'operator""_no_such_suffix'}}
94 _no_such_suffix
; // expected-error {{'operator""_no_such_suffix'}}
96 // Make sure we handle more interesting ways of writing a string literal which
97 // is "" in translation phase 7.
99 " _foo(unsigned long long); // ok
101 void operator R
"xyzzy()xyzzy" _foo(long double); // ok
103 void operator"" "" R
"()" "" _foo(const char *); // ok
105 void operator ""_no_space(const char *); // ok
107 // Ensure we diagnose the bad cases.
108 void operator "\0" _non_empty(const char *); // expected-error {{must be '""'}}
109 void operator L
"" _not_char(const char *); // expected-error {{cannot have an encoding prefix}}
111 U
"" // expected-error {{cannot have an encoding prefix}}
112 "" _also_not_char(const char *);
113 void operator "" u8
"" "\u0123" "hello"_all_of_the_things
""(const char*); // expected-error {{must be '""'}}
115 // Make sure we treat UCNs and UTF-8 as equivalent.
116 int operator""_µ
s(unsigned long long) {} // expected-note {{previous}}
117 int hundred_µs
= 50_µs
+ 50_
\u00b5s
;
118 int operator""_
\u00b5s
(unsigned long long) {} // expected-error {{redefinition of 'operator""_µs'}}
120 int operator""_\
U0000212B(long double) {} // expected-note {{previous}}
121 int hundred_Å
= 50.0_Å
+ 50._\U0000212B
;
122 int operator""_Å
(long double) {} // expected-error {{redefinition of 'operator""_Å'}}
124 int operator""_𐀀
(char) {} // expected-note {{previous}}
125 int 𐀀
= '4'_𐀀
+ '2'_\U00010000
;
126 int operator""_\
U00010000(char) {} // expected-error {{redefinition of 'operator""_𐀀'}}
128 // These all declare the same function.
129 int operator""_℮
""_
\u212e""_\U0000212e
""(const char*, size_t);
130 int operator""_
\u212e""_\U0000212e
""_℮
""(const char*, size_t);
131 int operator""_\U0000212e
""_℮
""_
\u212e""(const char*, size_t);
133 int operator""_\u
{212f
}(char);
134 int operator""_\N
{SCRIPT SMALL E
}(char);
136 int mix_ucn_utf8
= ""_℮
""_
\u212e""_\U0000212e
"";
138 void operator""_℮
""_ℯ
(unsigned long long) {} // expected-error {{differing user-defined suffixes ('_℮' and '_ℯ') in string literal concatenation}}
139 void operator""_℮
""_
\u212f(unsigned long long) {} // expected-error {{differing user-defined suffixes ('_℮' and '_ℯ') in string literal concatenation}}
140 void operator""_
\u212e""_ℯ
(unsigned long long) {} // expected-error {{differing user-defined suffixes ('_℮' and '_ℯ') in string literal concatenation}}
141 void operator""_
\u212e""_
\u212f(unsigned long long) {} // expected-error {{differing user-defined suffixes ('_℮' and '_ℯ') in string literal concatenation}}
143 void operator""_℮
""_℮
(unsigned long long) {} // expected-note {{previous}}
144 void operator""_
\u212e""_
\u212e(unsigned long long) {} // expected-error {{redefinition}}
146 #define ¢ *0.01 // expected-error {{macro name must be an identifier}}
147 constexpr int operator""_¢
(long double d
) { return d
* 100; } // expected-error {{character <U+00A2> not allowed in an identifier}}
148 constexpr int operator""_¢
(unsigned long long n
) { return n
; } // expected-error {{character <U+00A2> not allowed in an identifier}}
149 static_assert(0.02_¢
== 2_¢
, ""); // expected-error 2{{character <U+00A2> not allowed in an identifier}}