Richard Smith | 99831e4 | 2012-03-06 03:21:47 +0000 | [diff] [blame] | 1 | // 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 | |
| 18 | extern "C++"_x {} // expected-error {{user-defined suffix cannot be used here}} expected-error {{unknown linkage language}} |
| 19 | |
| 20 | int f() { |
| 21 | asm("mov %eax, %rdx"_foo); // expected-error {{user-defined suffix cannot be used here}} |
| 22 | } |
| 23 | |
| 24 | static_assert(true, "foo"_bar); // expected-error {{user-defined suffix cannot be used here}} |
| 25 | |
| 26 | int 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. |
| 35 | constexpr char operator"" _id(char c) { return c; } |
| 36 | constexpr wchar_t operator"" _id(wchar_t c) { return c; } |
| 37 | constexpr char16_t operator"" _id(char16_t c) { return c; } |
| 38 | constexpr char32_t operator"" _id(char32_t c) { return c; } |
| 39 | |
| 40 | using size_t = decltype(sizeof(int)); |
| 41 | constexpr const char operator"" _id(const char *p, size_t n) { return *p; } |
| 42 | constexpr const wchar_t operator"" _id(const wchar_t *p, size_t n) { return *p; } |
| 43 | constexpr const char16_t operator"" _id(const char16_t *p, size_t n) { return *p; } |
| 44 | constexpr const char32_t operator"" _id(const char32_t *p, size_t n) { return *p; } |
| 45 | |
| 46 | template<int n> struct S {}; |
| 47 | S<"a"_id[0]> sa; |
| 48 | S<L"b"_id[0]> sb; |
| 49 | S<u8"c"_id[0]> sc; |
| 50 | S<u"d"_id[0]> sd; |
| 51 | S<U"e"_id[0]> se; |
| 52 | |
| 53 | S<'w'_id> sw; |
| 54 | S<L'x'_id> sx; |
| 55 | S<u'y'_id> sy; |
| 56 | S<U'z'_id> sz; |
| 57 | |
| 58 | void h() { |
| 59 | (void)"test"_id "test" L"test"; |
| 60 | } |