diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-06 03:21:47 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-06 03:21:47 +0000 |
commit | 99831e4677a7e2e051af636221694d60ba31fcdb (patch) | |
tree | 4684bde38a7659db0c97673dcab98cffce576f9b /test | |
parent | c1b0f7fa9b755ab59129ae85187d0d4f91379995 (diff) |
User-defined literals: reject string and character UDLs in all places where the
grammar requires a string-literal and not a user-defined-string-literal. The
two constructs are still represented by the same TokenKind, in order to prevent
a combinatorial explosion of different kinds of token. A flag on Token tracks
whether a ud-suffix is present, in order to prevent clients from needing to look
at the token's spelling.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152098 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/CXX/over/over.oper/over.literal/p8.cpp | 2 | ||||
-rw-r--r-- | test/Lexer/token-concat.cpp | 19 | ||||
-rw-r--r-- | test/Parser/asm.cpp | 8 | ||||
-rw-r--r-- | test/Parser/cxx11-user-defined-literals.cpp | 60 | ||||
-rw-r--r-- | test/Parser/objcxx11-user-defined-literal.mm | 3 |
5 files changed, 91 insertions, 1 deletions
diff --git a/test/CXX/over/over.oper/over.literal/p8.cpp b/test/CXX/over/over.oper/over.literal/p8.cpp index 69d4e761e5..1837aafc7b 100644 --- a/test/CXX/over/over.oper/over.literal/p8.cpp +++ b/test/CXX/over/over.oper/over.literal/p8.cpp @@ -10,7 +10,7 @@ string operator "" _i18n(const char*, std::size_t); // ok // FIXME: This should be accepted once we support UCNs template<char...> int operator "" \u03C0(); // ok, UCN for lowercase pi // expected-error {{expected identifier}} // FIXME: Accept this as an extension, with a fix-it to add the space -float operator ""E(const char *); // expected-error {{must be '""'}} expected-error {{expected identifier}} +float operator ""E(const char *); // expected-error {{C++11 requires a space between the "" and the user-defined suffix in a literal operator}} float operator " " B(const char *); // expected-error {{must be '""'}} expected-warning {{hexfloat}} string operator "" 5X(const char *, std::size_t); // expected-error {{expected identifier}} double operator "" _miles(double); // expected-error {{parameter}} diff --git a/test/Lexer/token-concat.cpp b/test/Lexer/token-concat.cpp new file mode 100644 index 0000000000..57dbae03c1 --- /dev/null +++ b/test/Lexer/token-concat.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -E -std=c++11 -o - %s | FileCheck %s + +#define id(x) x +id("s")_x // CHECK: "s" _x +id(L"s")_x // CHECK: L"s" _x +id(u8"s")_x // CHECK: u8"s" _x +id(u"s")_x // CHECK: u"s" _x +id(U"s")_x // CHECK: U"s" _x +id('s')_x // CHECK: 's' _x +id(L's')_x // CHECK: L's' _x +id(u's')_x // CHECK: u's' _x +id(U's')_x // CHECK: U's' _x +id("s"_x)_y // CHECK: "s"_x _y +id(1.0_)f // CHECK: 1.0_ f +id(1.0)_f // CHECK: 1.0 _f +id(0xface+)b_count // CHECK: 0xface+ b_count +id("s")1 // CHECK: "s"1 +id("s"_x)1 // CHECK: "s"_x 1 +id(1)_2_x // CHECK: 1 _2_x diff --git a/test/Parser/asm.cpp b/test/Parser/asm.cpp new file mode 100644 index 0000000000..35a497c83a --- /dev/null +++ b/test/Parser/asm.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +int foo1 asm ("bar1"); +int foo2 asm (L"bar2"); // expected-error {{cannot use wide string literal in 'asm'}} +int foo3 asm (u8"bar3"); // expected-error {{cannot use unicode string literal in 'asm'}} +int foo4 asm (u"bar4"); // expected-error {{cannot use unicode string literal in 'asm'}} +int foo5 asm (U"bar5"); // expected-error {{cannot use unicode string literal in 'asm'}} +int foo6 asm ("bar6"_x); // expected-error {{string literal with user-defined suffix cannot be used here}} diff --git a/test/Parser/cxx11-user-defined-literals.cpp b/test/Parser/cxx11-user-defined-literals.cpp new file mode 100644 index 0000000000..c2d5af5c1d --- /dev/null +++ b/test/Parser/cxx11-user-defined-literals.cpp @@ -0,0 +1,60 @@ +// RUN: %clang_cc1 -std=c++11 -verify %s -fms-extensions -triple x86_64-apple-darwin9.0.0 + +// A ud-suffix cannot be used on string literals in a whole bunch of contexts: + +#include "foo"_bar // expected-error {{expected "FILENAME" or <FILENAME>}} +#line 1 "foo"_bar // expected-error {{user-defined suffix cannot be used here}} +# 1 "foo"_bar 1 // expected-error {{user-defined suffix cannot be used here}} +#ident "foo"_bar // expected-error {{user-defined suffix cannot be used here}} +_Pragma("foo"_bar) // expected-error {{user-defined suffix cannot be used here}} +#pragma comment(lib, "foo"_bar) // expected-error {{user-defined suffix cannot be used here}} +_Pragma("comment(lib, \"foo\"_bar)") // expected-error {{user-defined suffix cannot be used here}} +#pragma message "hi"_there // expected-error {{user-defined suffix cannot be used here}} expected-warning {{hi}} +#pragma push_macro("foo"_bar) // expected-error {{user-defined suffix cannot be used here}} +#if __has_warning("-Wan-island-to-discover"_bar) // expected-error {{user-defined suffix cannot be used here}} +#elif __has_include("foo"_bar) // expected-error {{expected "FILENAME" or <FILENAME>}} +#endif + +extern "C++"_x {} // expected-error {{user-defined suffix cannot be used here}} expected-error {{unknown linkage language}} + +int f() { + asm("mov %eax, %rdx"_foo); // expected-error {{user-defined suffix cannot be used here}} +} + +static_assert(true, "foo"_bar); // expected-error {{user-defined suffix cannot be used here}} + +int cake() __attribute__((availability(macosx, unavailable, message = "is a lie"_x))); // expected-error {{user-defined suffix cannot be used here}} + +// A ud-suffix cannot be used on character literals in preprocessor constant +// expressions: +#if 'x'_y - u'x'_z // expected-error 2{{character literal with user-defined suffix cannot be used in preprocessor constant expression}} +#error error +#endif + +// But they can appear in expressions. +constexpr char operator"" _id(char c) { return c; } +constexpr wchar_t operator"" _id(wchar_t c) { return c; } +constexpr char16_t operator"" _id(char16_t c) { return c; } +constexpr char32_t operator"" _id(char32_t c) { return c; } + +using size_t = decltype(sizeof(int)); +constexpr const char operator"" _id(const char *p, size_t n) { return *p; } +constexpr const wchar_t operator"" _id(const wchar_t *p, size_t n) { return *p; } +constexpr const char16_t operator"" _id(const char16_t *p, size_t n) { return *p; } +constexpr const char32_t operator"" _id(const char32_t *p, size_t n) { return *p; } + +template<int n> struct S {}; +S<"a"_id[0]> sa; +S<L"b"_id[0]> sb; +S<u8"c"_id[0]> sc; +S<u"d"_id[0]> sd; +S<U"e"_id[0]> se; + +S<'w'_id> sw; +S<L'x'_id> sx; +S<u'y'_id> sy; +S<U'z'_id> sz; + +void h() { + (void)"test"_id "test" L"test"; +} diff --git a/test/Parser/objcxx11-user-defined-literal.mm b/test/Parser/objcxx11-user-defined-literal.mm new file mode 100644 index 0000000000..a5f1397530 --- /dev/null +++ b/test/Parser/objcxx11-user-defined-literal.mm @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +id x = @"foo"_bar; // expected-error{{user-defined suffix cannot be used here}} |