199831e4677a7e2e051af636221694d60ba31fcdbRichard Smith// RUN: %clang_cc1 -std=c++11 -verify %s -fms-extensions -triple x86_64-apple-darwin9.0.0 299831e4677a7e2e051af636221694d60ba31fcdbRichard Smith 399831e4677a7e2e051af636221694d60ba31fcdbRichard Smith// A ud-suffix cannot be used on string literals in a whole bunch of contexts: 499831e4677a7e2e051af636221694d60ba31fcdbRichard Smith 599831e4677a7e2e051af636221694d60ba31fcdbRichard Smith#include "foo"_bar // expected-error {{expected "FILENAME" or <FILENAME>}} 699831e4677a7e2e051af636221694d60ba31fcdbRichard Smith#line 1 "foo"_bar // expected-error {{user-defined suffix cannot be used here}} 799831e4677a7e2e051af636221694d60ba31fcdbRichard Smith# 1 "foo"_bar 1 // expected-error {{user-defined suffix cannot be used here}} 899831e4677a7e2e051af636221694d60ba31fcdbRichard Smith#ident "foo"_bar // expected-error {{user-defined suffix cannot be used here}} 999831e4677a7e2e051af636221694d60ba31fcdbRichard Smith_Pragma("foo"_bar) // expected-error {{user-defined suffix cannot be used here}} 1099831e4677a7e2e051af636221694d60ba31fcdbRichard Smith#pragma comment(lib, "foo"_bar) // expected-error {{user-defined suffix cannot be used here}} 1199831e4677a7e2e051af636221694d60ba31fcdbRichard Smith_Pragma("comment(lib, \"foo\"_bar)") // expected-error {{user-defined suffix cannot be used here}} 1299831e4677a7e2e051af636221694d60ba31fcdbRichard Smith#pragma message "hi"_there // expected-error {{user-defined suffix cannot be used here}} expected-warning {{hi}} 1399831e4677a7e2e051af636221694d60ba31fcdbRichard Smith#pragma push_macro("foo"_bar) // expected-error {{user-defined suffix cannot be used here}} 1499831e4677a7e2e051af636221694d60ba31fcdbRichard Smith#if __has_warning("-Wan-island-to-discover"_bar) // expected-error {{user-defined suffix cannot be used here}} 1599831e4677a7e2e051af636221694d60ba31fcdbRichard Smith#elif __has_include("foo"_bar) // expected-error {{expected "FILENAME" or <FILENAME>}} 1699831e4677a7e2e051af636221694d60ba31fcdbRichard Smith#endif 1799831e4677a7e2e051af636221694d60ba31fcdbRichard Smith 1899831e4677a7e2e051af636221694d60ba31fcdbRichard Smithextern "C++"_x {} // expected-error {{user-defined suffix cannot be used here}} expected-error {{unknown linkage language}} 1999831e4677a7e2e051af636221694d60ba31fcdbRichard Smith 2099831e4677a7e2e051af636221694d60ba31fcdbRichard Smithint f() { 2199831e4677a7e2e051af636221694d60ba31fcdbRichard Smith asm("mov %eax, %rdx"_foo); // expected-error {{user-defined suffix cannot be used here}} 2299831e4677a7e2e051af636221694d60ba31fcdbRichard Smith} 2399831e4677a7e2e051af636221694d60ba31fcdbRichard Smith 2499831e4677a7e2e051af636221694d60ba31fcdbRichard Smithstatic_assert(true, "foo"_bar); // expected-error {{user-defined suffix cannot be used here}} 2599831e4677a7e2e051af636221694d60ba31fcdbRichard Smith 2699831e4677a7e2e051af636221694d60ba31fcdbRichard Smithint cake() __attribute__((availability(macosx, unavailable, message = "is a lie"_x))); // expected-error {{user-defined suffix cannot be used here}} 2799831e4677a7e2e051af636221694d60ba31fcdbRichard Smith 2899831e4677a7e2e051af636221694d60ba31fcdbRichard Smith// A ud-suffix cannot be used on character literals in preprocessor constant 2999831e4677a7e2e051af636221694d60ba31fcdbRichard Smith// expressions: 3099831e4677a7e2e051af636221694d60ba31fcdbRichard Smith#if 'x'_y - u'x'_z // expected-error 2{{character literal with user-defined suffix cannot be used in preprocessor constant expression}} 3199831e4677a7e2e051af636221694d60ba31fcdbRichard Smith#error error 3299831e4677a7e2e051af636221694d60ba31fcdbRichard Smith#endif 3399831e4677a7e2e051af636221694d60ba31fcdbRichard Smith 34b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smith// A ud-suffix cannot be used on integer literals in preprocessor constant 35b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smith// expressions: 36b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smith#if 0_foo // expected-error {{integer literal with user-defined suffix cannot be used in preprocessor constant expression}} 37b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smith#error error 38b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smith#endif 39b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smith 4099831e4677a7e2e051af636221694d60ba31fcdbRichard Smith// But they can appear in expressions. 4199831e4677a7e2e051af636221694d60ba31fcdbRichard Smithconstexpr char operator"" _id(char c) { return c; } 4299831e4677a7e2e051af636221694d60ba31fcdbRichard Smithconstexpr wchar_t operator"" _id(wchar_t c) { return c; } 4399831e4677a7e2e051af636221694d60ba31fcdbRichard Smithconstexpr char16_t operator"" _id(char16_t c) { return c; } 4499831e4677a7e2e051af636221694d60ba31fcdbRichard Smithconstexpr char32_t operator"" _id(char32_t c) { return c; } 4599831e4677a7e2e051af636221694d60ba31fcdbRichard Smith 4699831e4677a7e2e051af636221694d60ba31fcdbRichard Smithusing size_t = decltype(sizeof(int)); 4799831e4677a7e2e051af636221694d60ba31fcdbRichard Smithconstexpr const char operator"" _id(const char *p, size_t n) { return *p; } 4899831e4677a7e2e051af636221694d60ba31fcdbRichard Smithconstexpr const wchar_t operator"" _id(const wchar_t *p, size_t n) { return *p; } 4999831e4677a7e2e051af636221694d60ba31fcdbRichard Smithconstexpr const char16_t operator"" _id(const char16_t *p, size_t n) { return *p; } 5099831e4677a7e2e051af636221694d60ba31fcdbRichard Smithconstexpr const char32_t operator"" _id(const char32_t *p, size_t n) { return *p; } 5199831e4677a7e2e051af636221694d60ba31fcdbRichard Smith 52b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smithconstexpr unsigned long long operator"" _id(unsigned long long n) { return n; } 53b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smithconstexpr long double operator"" _id(long double d) { return d; } 54b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smith 5599831e4677a7e2e051af636221694d60ba31fcdbRichard Smithtemplate<int n> struct S {}; 569fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard SmithS<"a"_id> sa; 579fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard SmithS<L"b"_id> sb; 589fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard SmithS<u8"c"_id> sc; 599fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard SmithS<u"d"_id> sd; 609fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard SmithS<U"e"_id> se; 6199831e4677a7e2e051af636221694d60ba31fcdbRichard Smith 6299831e4677a7e2e051af636221694d60ba31fcdbRichard SmithS<'w'_id> sw; 6399831e4677a7e2e051af636221694d60ba31fcdbRichard SmithS<L'x'_id> sx; 6499831e4677a7e2e051af636221694d60ba31fcdbRichard SmithS<u'y'_id> sy; 6599831e4677a7e2e051af636221694d60ba31fcdbRichard SmithS<U'z'_id> sz; 6699831e4677a7e2e051af636221694d60ba31fcdbRichard Smith 67b453ad3214d00acc51c9aa702c76c58354d84b84Richard SmithS<100_id> sn; 68b453ad3214d00acc51c9aa702c76c58354d84b84Richard SmithS<(int)1.3_id> sf; 69b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smith 7099831e4677a7e2e051af636221694d60ba31fcdbRichard Smithvoid h() { 7199831e4677a7e2e051af636221694d60ba31fcdbRichard Smith (void)"test"_id "test" L"test"; 7299831e4677a7e2e051af636221694d60ba31fcdbRichard Smith} 739fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 74dd66be718f23c8149d74ae8b011b002e11e8d5baRichard Smith// Test source location for suffix is known 75dd66be718f23c8149d74ae8b011b002e11e8d5baRichard Smithconst char *p = 76dd66be718f23c8149d74ae8b011b002e11e8d5baRichard Smith "foo\nbar" R"x( 77dd66be718f23c8149d74ae8b011b002e11e8d5baRichard Smith erk 78dd66be718f23c8149d74ae8b011b002e11e8d5baRichard Smith flux 79dd66be718f23c8149d74ae8b011b002e11e8d5baRichard Smith )x" "eep\x1f"\ 8036f5cfe4df32af6c5fe01228102512996f566f9dRichard Smith_no_such_suffix // expected-error {{'operator "" _no_such_suffix'}} 81dd66be718f23c8149d74ae8b011b002e11e8d5baRichard Smith"and a bit more" 82dd66be718f23c8149d74ae8b011b002e11e8d5baRichard Smith"and another suffix"_no_such_suffix; 83dd66be718f23c8149d74ae8b011b002e11e8d5baRichard Smith 84dd66be718f23c8149d74ae8b011b002e11e8d5baRichard Smithchar c = 85dd66be718f23c8149d74ae8b011b002e11e8d5baRichard Smith '\x14'\ 8636f5cfe4df32af6c5fe01228102512996f566f9dRichard Smith_no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}} 87b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smith 88b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smithint &r = 89b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smith1234567\ 9036f5cfe4df32af6c5fe01228102512996f566f9dRichard Smith_no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}} 91b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smith 92b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smithint k = 93b453ad3214d00acc51c9aa702c76c58354d84b84Richard Smith1234567.89\ 9436f5cfe4df32af6c5fe01228102512996f566f9dRichard Smith_no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}} 9533762775706e81c17ca774102ceda36049ecc593Richard Smith 9633762775706e81c17ca774102ceda36049ecc593Richard Smith// Make sure we handle more interesting ways of writing a string literal which 9733762775706e81c17ca774102ceda36049ecc593Richard Smith// is "" in translation phase 7. 9833762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator "\ 9933762775706e81c17ca774102ceda36049ecc593Richard Smith" _foo(unsigned long long); // ok 10033762775706e81c17ca774102ceda36049ecc593Richard Smith 10133762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator R"xyzzy()xyzzy" _foo(long double); // ok 10233762775706e81c17ca774102ceda36049ecc593Richard Smith 10333762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator"" "" R"()" "" _foo(const char *); // ok 10433762775706e81c17ca774102ceda36049ecc593Richard Smith 10533762775706e81c17ca774102ceda36049ecc593Richard Smith// Ensure we diagnose the bad cases. 10633762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator "\0" _non_empty(const char *); // expected-error {{must be '""'}} 10733762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator ""_no_space(const char *); // expected-error {{C++11 requires a space}} 10833762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator L"" _not_char(const char *); // expected-error {{cannot have an encoding prefix}} 10933762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator "" "" 11033762775706e81c17ca774102ceda36049ecc593Richard SmithU"" // expected-error {{cannot have an encoding prefix}} 11133762775706e81c17ca774102ceda36049ecc593Richard Smith"" _also_not_char(const char *); 11233762775706e81c17ca774102ceda36049ecc593Richard Smithvoid operator "" u8"" "\u0123" "hello"_all_of_the_things ""(const char*); // expected-error {{must be '""'}} 113