1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -verify %s -fms-extensions -triple x86_64-apple-darwin9.0.0
2f4a2713aSLionel Sambuc
3f4a2713aSLionel Sambuc // A ud-suffix cannot be used on string literals in a whole bunch of contexts:
4f4a2713aSLionel Sambuc
5f4a2713aSLionel Sambuc #include "foo"_bar // expected-error {{expected "FILENAME" or <FILENAME>}}
6f4a2713aSLionel Sambuc #line 1 "foo"_bar // expected-error {{user-defined suffix cannot be used here}}
7f4a2713aSLionel Sambuc # 1 "foo"_bar 1 // expected-error {{user-defined suffix cannot be used here}}
8f4a2713aSLionel Sambuc #ident "foo"_bar // expected-error {{user-defined suffix cannot be used here}}
9f4a2713aSLionel Sambuc _Pragma("foo"_bar) // expected-error {{user-defined suffix cannot be used here}}
10f4a2713aSLionel Sambuc #pragma comment(lib, "foo"_bar) // expected-error {{user-defined suffix cannot be used here}}
11f4a2713aSLionel Sambuc _Pragma("comment(lib, \"foo\"_bar)") // expected-error {{user-defined suffix cannot be used here}}
12f4a2713aSLionel Sambuc #pragma message "hi"_there // expected-error {{user-defined suffix cannot be used here}} expected-warning {{hi}}
13f4a2713aSLionel Sambuc #pragma push_macro("foo"_bar) // expected-error {{user-defined suffix cannot be used here}}
14f4a2713aSLionel Sambuc #if __has_warning("-Wan-island-to-discover"_bar) // expected-error {{user-defined suffix cannot be used here}}
15f4a2713aSLionel Sambuc #elif __has_include("foo"_bar) // expected-error {{expected "FILENAME" or <FILENAME>}}
16f4a2713aSLionel Sambuc #endif
17f4a2713aSLionel Sambuc
18*0a6a1f1dSLionel Sambuc extern "C++"_x {} // expected-error {{user-defined suffix cannot be used here}}
19f4a2713aSLionel Sambuc
f()20f4a2713aSLionel Sambuc int f() {
21f4a2713aSLionel Sambuc asm("mov %eax, %rdx"_foo); // expected-error {{user-defined suffix cannot be used here}}
22f4a2713aSLionel Sambuc }
23f4a2713aSLionel Sambuc
24f4a2713aSLionel Sambuc static_assert(true, "foo"_bar); // expected-error {{user-defined suffix cannot be used here}}
25f4a2713aSLionel Sambuc
26f4a2713aSLionel Sambuc int cake() __attribute__((availability(macosx, unavailable, message = "is a lie"_x))); // expected-error {{user-defined suffix cannot be used here}}
27f4a2713aSLionel Sambuc
28f4a2713aSLionel Sambuc // A ud-suffix cannot be used on character literals in preprocessor constant
29f4a2713aSLionel Sambuc // expressions:
30f4a2713aSLionel Sambuc #if 'x'_y - u'x'_z // expected-error 2{{character literal with user-defined suffix cannot be used in preprocessor constant expression}}
31f4a2713aSLionel Sambuc #error error
32f4a2713aSLionel Sambuc #endif
33f4a2713aSLionel Sambuc
34f4a2713aSLionel Sambuc // A ud-suffix cannot be used on integer literals in preprocessor constant
35f4a2713aSLionel Sambuc // expressions:
36f4a2713aSLionel Sambuc #if 0_foo // expected-error {{integer literal with user-defined suffix cannot be used in preprocessor constant expression}}
37f4a2713aSLionel Sambuc #error error
38f4a2713aSLionel Sambuc #endif
39f4a2713aSLionel Sambuc
40f4a2713aSLionel Sambuc // But they can appear in expressions.
operator ""_id(char c)41f4a2713aSLionel Sambuc constexpr char operator"" _id(char c) { return c; }
operator ""_id(wchar_t c)42f4a2713aSLionel Sambuc constexpr wchar_t operator"" _id(wchar_t c) { return c; }
operator ""_id(char16_t c)43f4a2713aSLionel Sambuc constexpr char16_t operator"" _id(char16_t c) { return c; }
operator ""_id(char32_t c)44f4a2713aSLionel Sambuc constexpr char32_t operator"" _id(char32_t c) { return c; }
45f4a2713aSLionel Sambuc
46f4a2713aSLionel Sambuc using size_t = decltype(sizeof(int));
operator ""_id(const char * p,size_t n)47f4a2713aSLionel Sambuc constexpr const char operator"" _id(const char *p, size_t n) { return *p; }
operator ""_id(const wchar_t * p,size_t n)48f4a2713aSLionel Sambuc constexpr const wchar_t operator"" _id(const wchar_t *p, size_t n) { return *p; }
operator ""_id(const char16_t * p,size_t n)49f4a2713aSLionel Sambuc constexpr const char16_t operator"" _id(const char16_t *p, size_t n) { return *p; }
operator ""_id(const char32_t * p,size_t n)50f4a2713aSLionel Sambuc constexpr const char32_t operator"" _id(const char32_t *p, size_t n) { return *p; }
51f4a2713aSLionel Sambuc
operator ""_id(unsigned long long n)52f4a2713aSLionel Sambuc constexpr unsigned long long operator"" _id(unsigned long long n) { return n; }
operator ""_id(long double d)53f4a2713aSLionel Sambuc constexpr long double operator"" _id(long double d) { return d; }
54f4a2713aSLionel Sambuc
55f4a2713aSLionel Sambuc template<int n> struct S {};
56f4a2713aSLionel Sambuc S<"a"_id> sa;
57f4a2713aSLionel Sambuc S<L"b"_id> sb;
58f4a2713aSLionel Sambuc S<u8"c"_id> sc;
59f4a2713aSLionel Sambuc S<u"d"_id> sd;
60f4a2713aSLionel Sambuc S<U"e"_id> se;
61f4a2713aSLionel Sambuc
62f4a2713aSLionel Sambuc S<'w'_id> sw;
63f4a2713aSLionel Sambuc S<L'x'_id> sx;
64f4a2713aSLionel Sambuc S<u'y'_id> sy;
65f4a2713aSLionel Sambuc S<U'z'_id> sz;
66f4a2713aSLionel Sambuc
67f4a2713aSLionel Sambuc S<100_id> sn;
68f4a2713aSLionel Sambuc S<(int)1.3_id> sf;
69f4a2713aSLionel Sambuc
h()70f4a2713aSLionel Sambuc void h() {
71f4a2713aSLionel Sambuc (void)"test"_id "test" L"test";
72f4a2713aSLionel Sambuc }
73f4a2713aSLionel Sambuc
74f4a2713aSLionel Sambuc // Test source location for suffix is known
75f4a2713aSLionel Sambuc const char *p =
76f4a2713aSLionel Sambuc "foo\nbar" R"x(
77f4a2713aSLionel Sambuc erk
78f4a2713aSLionel Sambuc flux
79f4a2713aSLionel Sambuc )x" "eep\x1f"\
80f4a2713aSLionel Sambuc _no_such_suffix // expected-error {{'operator "" _no_such_suffix'}}
81f4a2713aSLionel Sambuc "and a bit more"
82f4a2713aSLionel Sambuc "and another suffix"_no_such_suffix;
83f4a2713aSLionel Sambuc
84f4a2713aSLionel Sambuc char c =
85f4a2713aSLionel Sambuc '\x14'\
86f4a2713aSLionel Sambuc _no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}}
87f4a2713aSLionel Sambuc
88f4a2713aSLionel Sambuc int &r =
89f4a2713aSLionel Sambuc 1234567\
90f4a2713aSLionel Sambuc _no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}}
91f4a2713aSLionel Sambuc
92f4a2713aSLionel Sambuc int k =
93f4a2713aSLionel Sambuc 1234567.89\
94f4a2713aSLionel Sambuc _no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}}
95f4a2713aSLionel Sambuc
96f4a2713aSLionel Sambuc // Make sure we handle more interesting ways of writing a string literal which
97f4a2713aSLionel Sambuc // is "" in translation phase 7.
98f4a2713aSLionel Sambuc void operator "\
99f4a2713aSLionel Sambuc " _foo(unsigned long long); // ok
100f4a2713aSLionel Sambuc
101f4a2713aSLionel Sambuc void operator R"xyzzy()xyzzy" _foo(long double); // ok
102f4a2713aSLionel Sambuc
103f4a2713aSLionel Sambuc void operator"" "" R"()" "" _foo(const char *); // ok
104f4a2713aSLionel Sambuc
105f4a2713aSLionel Sambuc void operator ""_no_space(const char *); // ok
106f4a2713aSLionel Sambuc
107f4a2713aSLionel Sambuc // Ensure we diagnose the bad cases.
108f4a2713aSLionel Sambuc void operator "\0" _non_empty(const char *); // expected-error {{must be '""'}}
109f4a2713aSLionel Sambuc void operator L"" _not_char(const char *); // expected-error {{cannot have an encoding prefix}}
110f4a2713aSLionel Sambuc void operator "" ""
111f4a2713aSLionel Sambuc U"" // expected-error {{cannot have an encoding prefix}}
112f4a2713aSLionel Sambuc "" _also_not_char(const char *);
113f4a2713aSLionel Sambuc void operator "" u8"" "\u0123" "hello"_all_of_the_things ""(const char*); // expected-error {{must be '""'}}
114*0a6a1f1dSLionel Sambuc
115*0a6a1f1dSLionel Sambuc // Make sure we treat UCNs and UTF-8 as equivalent.
116*0a6a1f1dSLionel Sambuc int operator""_µs(unsigned long long) {} // expected-note {{previous}}
117*0a6a1f1dSLionel Sambuc int hundred_µs = 50_µs + 50_\u00b5s;
118*0a6a1f1dSLionel Sambuc int operator""_\u00b5s(unsigned long long) {} // expected-error {{redefinition of 'operator "" _µs'}}
119*0a6a1f1dSLionel Sambuc
120*0a6a1f1dSLionel Sambuc int operator""_\U0000212B(long double) {} // expected-note {{previous}}
121*0a6a1f1dSLionel Sambuc int hundred_Å = 50.0_Å + 50._\U0000212B;
122*0a6a1f1dSLionel Sambuc int operator""_Å(long double) {} // expected-error {{redefinition of 'operator "" _Å'}}
123*0a6a1f1dSLionel Sambuc
124*0a6a1f1dSLionel Sambuc int operator""_(char) {} // expected-note {{previous}}
125*0a6a1f1dSLionel Sambuc int = '4'_ + '2'_\U00010000;
126*0a6a1f1dSLionel Sambuc int operator""_\U00010000(char) {} // expected-error {{redefinition of 'operator "" _'}}
127*0a6a1f1dSLionel Sambuc
128*0a6a1f1dSLionel Sambuc // These all declare the same function.
129*0a6a1f1dSLionel Sambuc int operator""_℮""_\u212e""_\U0000212e""(const char*, size_t);
130*0a6a1f1dSLionel Sambuc int operator""_\u212e""_\U0000212e""_℮""(const char*, size_t);
131*0a6a1f1dSLionel Sambuc int operator""_\U0000212e""_℮""_\u212e""(const char*, size_t);
132*0a6a1f1dSLionel Sambuc int mix_ucn_utf8 = ""_℮""_\u212e""_\U0000212e"";
133*0a6a1f1dSLionel Sambuc
134*0a6a1f1dSLionel Sambuc void operator""_℮""_ℯ(unsigned long long) {} // expected-error {{differing user-defined suffixes ('_℮' and '_ℯ') in string literal concatenation}}
135*0a6a1f1dSLionel Sambuc void operator""_℮""_\u212f(unsigned long long) {} // expected-error {{differing user-defined suffixes ('_℮' and '_ℯ') in string literal concatenation}}
136*0a6a1f1dSLionel Sambuc void operator""_\u212e""_ℯ(unsigned long long) {} // expected-error {{differing user-defined suffixes ('_℮' and '_ℯ') in string literal concatenation}}
137*0a6a1f1dSLionel Sambuc void operator""_\u212e""_\u212f(unsigned long long) {} // expected-error {{differing user-defined suffixes ('_℮' and '_ℯ') in string literal concatenation}}
138*0a6a1f1dSLionel Sambuc
139*0a6a1f1dSLionel Sambuc void operator""_℮""_℮(unsigned long long) {} // expected-note {{previous}}
140*0a6a1f1dSLionel Sambuc void operator""_\u212e""_\u212e(unsigned long long) {} // expected-error {{redefinition}}
141*0a6a1f1dSLionel Sambuc
142*0a6a1f1dSLionel Sambuc #define ¢ *0.01 // expected-error {{macro name must be an identifier}}
143*0a6a1f1dSLionel Sambuc constexpr int operator""_¢(long double d) { return d * 100; } // expected-error {{non-ASCII}}
144*0a6a1f1dSLionel Sambuc constexpr int operator""_¢(unsigned long long n) { return n; } // expected-error {{non-ASCII}}
145*0a6a1f1dSLionel Sambuc static_assert(0.02_¢ == 2_¢, ""); // expected-error 2{{non-ASCII}}
146