blob: c2d5af5c1deadfc02f2d5e7b29e95d058090c026 [file] [log] [blame]
Richard Smith99831e42012-03-06 03:21:47 +00001// RUN: %clang_cc1 -std=c++11 -verify %s -fms-extensions -triple x86_64-apple-darwin9.0.0
2
3// A ud-suffix cannot be used on string literals in a whole bunch of contexts:
4
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>}}
16#endif
17
18extern "C++"_x {} // expected-error {{user-defined suffix cannot be used here}} expected-error {{unknown linkage language}}
19
20int f() {
21 asm("mov %eax, %rdx"_foo); // expected-error {{user-defined suffix cannot be used here}}
22}
23
24static_assert(true, "foo"_bar); // expected-error {{user-defined suffix cannot be used here}}
25
26int cake() __attribute__((availability(macosx, unavailable, message = "is a lie"_x))); // expected-error {{user-defined suffix cannot be used here}}
27
28// A ud-suffix cannot be used on character literals in preprocessor constant
29// expressions:
30#if 'x'_y - u'x'_z // expected-error 2{{character literal with user-defined suffix cannot be used in preprocessor constant expression}}
31#error error
32#endif
33
34// But they can appear in expressions.
35constexpr char operator"" _id(char c) { return c; }
36constexpr wchar_t operator"" _id(wchar_t c) { return c; }
37constexpr char16_t operator"" _id(char16_t c) { return c; }
38constexpr char32_t operator"" _id(char32_t c) { return c; }
39
40using size_t = decltype(sizeof(int));
41constexpr const char operator"" _id(const char *p, size_t n) { return *p; }
42constexpr const wchar_t operator"" _id(const wchar_t *p, size_t n) { return *p; }
43constexpr const char16_t operator"" _id(const char16_t *p, size_t n) { return *p; }
44constexpr const char32_t operator"" _id(const char32_t *p, size_t n) { return *p; }
45
46template<int n> struct S {};
47S<"a"_id[0]> sa;
48S<L"b"_id[0]> sb;
49S<u8"c"_id[0]> sc;
50S<u"d"_id[0]> sd;
51S<U"e"_id[0]> se;
52
53S<'w'_id> sw;
54S<L'x'_id> sx;
55S<u'y'_id> sy;
56S<U'z'_id> sz;
57
58void h() {
59 (void)"test"_id "test" L"test";
60}