diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-08 08:45:32 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-08 08:45:32 +0000 |
commit | b453ad3214d00acc51c9aa702c76c58354d84b84 (patch) | |
tree | fbf7b0f3c7bf20b921b60a43a544a87c8968cc05 /test/Parser/cxx11-user-defined-literals.cpp | |
parent | aae1d8bd6f2482e0bf13a29d5b0cb7639080974d (diff) | |
download | clang-b453ad3214d00acc51c9aa702c76c58354d84b84.tar.gz |
Add support for cooked forms of user-defined-integer-literal and
user-defined-floating-literal. Support for raw forms of these literals
to follow.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152302 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Parser/cxx11-user-defined-literals.cpp')
-rw-r--r-- | test/Parser/cxx11-user-defined-literals.cpp | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/test/Parser/cxx11-user-defined-literals.cpp b/test/Parser/cxx11-user-defined-literals.cpp index 80ff741ba0..b34680d080 100644 --- a/test/Parser/cxx11-user-defined-literals.cpp +++ b/test/Parser/cxx11-user-defined-literals.cpp @@ -31,6 +31,12 @@ int cake() __attribute__((availability(macosx, unavailable, message = "is a lie" #error error #endif +// A ud-suffix cannot be used on integer literals in preprocessor constant +// expressions: +#if 0_foo // expected-error {{integer 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; } @@ -43,6 +49,9 @@ 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; } +constexpr unsigned long long operator"" _id(unsigned long long n) { return n; } +constexpr long double operator"" _id(long double d) { return d; } + template<int n> struct S {}; S<"a"_id> sa; S<L"b"_id> sb; @@ -55,30 +64,13 @@ S<L'x'_id> sx; S<u'y'_id> sy; S<U'z'_id> sz; +S<100_id> sn; +S<(int)1.3_id> sf; + void h() { (void)"test"_id "test" L"test"; } -enum class LitKind { Char, WideChar, Char16, Char32, CharStr, WideStr, Char16Str, Char32Str }; -constexpr LitKind operator"" _kind(char p) { return LitKind::Char; } -constexpr LitKind operator"" _kind(wchar_t p) { return LitKind::WideChar; } -constexpr LitKind operator"" _kind(char16_t p) { return LitKind::Char16; } -constexpr LitKind operator"" _kind(char32_t p) { return LitKind::Char32; } -constexpr LitKind operator"" _kind(const char *p, size_t n) { return LitKind::CharStr; } -constexpr LitKind operator"" _kind(const wchar_t *p, size_t n) { return LitKind::WideStr; } -constexpr LitKind operator"" _kind(const char16_t *p, size_t n) { return LitKind::Char16Str; } -constexpr LitKind operator"" _kind(const char32_t *p, size_t n) { return LitKind::Char32Str; } - -static_assert('x'_kind == LitKind::Char, ""); -static_assert(L'x'_kind == LitKind::WideChar, ""); -static_assert(u'x'_kind == LitKind::Char16, ""); -static_assert(U'x'_kind == LitKind::Char32, ""); -static_assert("foo"_kind == LitKind::CharStr, ""); -static_assert(u8"foo"_kind == LitKind::CharStr, ""); -static_assert(L"foo"_kind == LitKind::WideStr, ""); -static_assert(u"foo"_kind == LitKind::Char16Str, ""); -static_assert(U"foo"_kind == LitKind::Char32Str, ""); - // Test source location for suffix is known const char *p = "foo\nbar" R"x( @@ -89,7 +81,14 @@ _no_such_suffix // expected-error {{'_no_such_suffix'}} "and a bit more" "and another suffix"_no_such_suffix; -// And for character literals char c = '\x14'\ _no_such_suffix; // expected-error {{'_no_such_suffix'}} + +int &r = +1234567\ +_no_such_suffix; // expected-error {{'_no_such_suffix'}} + +int k = +1234567.89\ +_no_such_suffix; // expected-error {{'_no_such_suffix'}} |