brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.9 KiB · 27a7181 Raw
154 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -verify %s -fms-extensions -triple x86_64-apple-darwin9.0.02 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#endif17 18extern "C++"_x {} // expected-error {{user-defined suffix cannot be used here}}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 {{no matching literal operator for call to 'operator""_bar'}}25// expected-warning@-1 {{'static_assert' with a user-generated message is a C++26 extension}}26 27int cake() __attribute__((availability(macosx, unavailable, message = "is a lie"_x))); // expected-error {{user-defined suffix cannot be used here}}28 29// A ud-suffix cannot be used on character literals in preprocessor constant30// expressions:31#if 'x'_y - u'x'_z // expected-error 2{{character literal with user-defined suffix cannot be used in preprocessor constant expression}}32#error error33#endif34 35// A ud-suffix cannot be used on integer literals in preprocessor constant36// expressions:37#if 0_foo // expected-error {{integer literal with user-defined suffix cannot be used in preprocessor constant expression}}38#error error39#endif40 41// But they can appear in expressions.42constexpr char operator""_id(char c) { return c; }43constexpr wchar_t operator""_id(wchar_t c) { return c; }44constexpr char16_t operator""_id(char16_t c) { return c; }45constexpr char32_t operator""_id(char32_t c) { return c; }46 47using size_t = decltype(sizeof(int));48constexpr const char operator""_id(const char *p, size_t n) { return *p; }49constexpr const wchar_t operator""_id(const wchar_t *p, size_t n) { return *p; }50constexpr const char16_t operator""_id(const char16_t *p, size_t n) { return *p; }51constexpr const char32_t operator""_id(const char32_t *p, size_t n) { return *p; }52 53constexpr unsigned long long operator""_id(unsigned long long n) { return n; }54constexpr long double operator""_id(long double d) { return d; }55 56template<int n> struct S {};57S<"a"_id> sa;58S<L"b"_id> sb;59S<u8"c"_id> sc;60S<u"d"_id> sd;61S<U"e"_id> se;62 63S<'w'_id> sw;64S<L'x'_id> sx;65S<u'y'_id> sy;66S<U'z'_id> sz;67 68S<100_id> sn;69S<(int)1.3_id> sf;70 71void h() {72  (void)"test"_id "test" L"test";73}74 75// Test source location for suffix is known76const char *p =77  "foo\nbar" R"x(78  erk79  flux80  )x" "eep\x1f"\81_no_such_suffix // expected-error {{'operator""_no_such_suffix'}}82"and a bit more"83"and another suffix"_no_such_suffix;84 85char c =86  '\x14'\87_no_such_suffix; // expected-error {{'operator""_no_such_suffix'}}88 89int &r =901234567\91_no_such_suffix; // expected-error {{'operator""_no_such_suffix'}}92 93int k =941234567.89\95_no_such_suffix; // expected-error {{'operator""_no_such_suffix'}}96 97// Make sure we handle more interesting ways of writing a string literal which98// is "" in translation phase 7.99void operator "\100" _foo(unsigned long long); // ok101// expected-warning@-1{{identifier '_foo' preceded by whitespace in a literal operator declaration is deprecated}}102 103void operator R"xyzzy()xyzzy" _foo(long double); // ok104// expected-warning@-1{{identifier '_foo' preceded by whitespace in a literal operator declaration is deprecated}}105 106void operator"" "" R"()" "" _foo(const char *); // ok107// expected-warning@-1{{identifier '_foo' preceded by whitespace}}108 109void operator ""_no_space(const char *); // ok110 111// Ensure we diagnose the bad cases.112void operator "\0"_non_empty(const char *); // expected-error {{must be '""'}}113void operator L""_not_char(const char *); // expected-error {{cannot have an encoding prefix}}114void operator "" ""115U"" // expected-error {{cannot have an encoding prefix}}116""_also_not_char(const char *);117void operator "" u8"" "\u0123" "hello"_all_of_the_things ""(const char*); // expected-error {{must be '""'}}118 119// Make sure we treat UCNs and UTF-8 as equivalent.120int operator""_µs(unsigned long long) {} // expected-note {{previous}}121int hundred_µs = 50_µs + 50_\u00b5s;122int operator""_\u00b5s(unsigned long long) {} // expected-error {{redefinition of 'operator""_µs'}}123 124int operator""_\U0000212B(long double) {} // expected-note {{previous}}125int hundred_Å = 50.0_Å + 50._\U0000212B;126int operator""_Å(long double) {} // expected-error {{redefinition of 'operator""_Å'}}127 128int operator""_𐀀(char) {} // expected-note {{previous}}129int 𐀀 = '4'_𐀀 + '2'_\U00010000;130int operator""_\U00010000(char) {} // expected-error {{redefinition of 'operator""_𐀀'}}131 132// These all declare the same function.133int operator""_℮""_\u212e""_\U0000212e""(const char*, size_t);134int operator""_\u212e""_\U0000212e""_℮""(const char*, size_t);135int operator""_\U0000212e""_℮""_\u212e""(const char*, size_t);136 137int operator""_\u{212f}(char);138int operator""_\N{SCRIPT SMALL E}(char);139 140int mix_ucn_utf8 = ""_℮""_\u212e""_\U0000212e"";141 142void operator""_℮""_ℯ(unsigned long long) {} // expected-error {{differing user-defined suffixes ('_℮' and '_ℯ') in string literal concatenation}}143void operator""_℮""_\u212f(unsigned long long) {} // expected-error {{differing user-defined suffixes ('_℮' and '_ℯ') in string literal concatenation}}144void operator""_\u212e""_ℯ(unsigned long long) {} // expected-error {{differing user-defined suffixes ('_℮' and '_ℯ') in string literal concatenation}}145void operator""_\u212e""_\u212f(unsigned long long) {} // expected-error {{differing user-defined suffixes ('_℮' and '_ℯ') in string literal concatenation}}146 147void operator""_℮""_℮(unsigned long long) {} // expected-note {{previous}}148void operator""_\u212e""_\u212e(unsigned long long) {} // expected-error {{redefinition}}149 150#define ¢ *0.01 // expected-error {{macro name must be an identifier}}151constexpr int operator""_¢(long double d) { return d * 100; }  // expected-error {{character <U+00A2> not allowed in an identifier}}152constexpr int operator""_¢(unsigned long long n) { return n; } // expected-error {{character <U+00A2> not allowed in an identifier}}153static_assert(0.02_¢ == 2_¢, "");                              // expected-error 2{{character <U+00A2> not allowed in an identifier}}154