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
diff --git a/test/CodeGenCXX/cxx11-user-defined-literal.cpp b/test/CodeGenCXX/cxx11-user-defined-literal.cpp
index 4bd49c8..647ea57 100644
--- a/test/CodeGenCXX/cxx11-user-defined-literal.cpp
+++ b/test/CodeGenCXX/cxx11-user-defined-literal.cpp
@@ -4,15 +4,21 @@
 using size_t = decltype(sizeof(int));
 S operator"" _x(const char *, size_t);
 S operator"" _y(wchar_t);
+S operator"" _z(unsigned long long);
+S operator"" _f(long double);
 
 void f() {
   // CHECK: call void @_Zli2_xPKcm({{.*}}, i8* getelementptr inbounds ([4 x i8]* @{{.*}}, i32 0, i32 0), i64 3)
   // CHECK: call void @_Zli2_xPKcm({{.*}}, i8* getelementptr inbounds ([4 x i8]* @{{.*}}, i32 0, i32 0), i64 3)
   // CHECK: call void @_Zli2_yw({{.*}} 97)
+  // CHECK: call void @_Zli2_zy({{.*}} 42)
+  // CHECK: call void @_Zli2_fe({{.*}} x86_fp80 0xK3FFF8000000000000000)
   // CHECK: call void @_ZN1SD1Ev({{.*}}) nounwind
   // CHECK: call void @_ZN1SD1Ev({{.*}}) nounwind
   // CHECK: call void @_ZN1SD1Ev({{.*}}) nounwind
-  "foo"_x, "bar"_x, L'a'_y;
+  // CHECK: call void @_ZN1SD1Ev({{.*}}) nounwind
+  // CHECK: call void @_ZN1SD1Ev({{.*}}) nounwind
+  "foo"_x, "bar"_x, L'a'_y, 42_z, 1.0_f;
 }
 
 template<typename T> auto g(T t) -> decltype("foo"_x(t)) { return "foo"_x(t); }
diff --git a/test/Parser/cxx11-user-defined-literals.cpp b/test/Parser/cxx11-user-defined-literals.cpp
index 80ff741..b34680d 100644
--- a/test/Parser/cxx11-user-defined-literals.cpp
+++ b/test/Parser/cxx11-user-defined-literals.cpp
@@ -31,6 +31,12 @@
 #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 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<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 @@
 "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'}}
diff --git a/test/SemaCXX/cxx11-user-defined-literals.cpp b/test/SemaCXX/cxx11-user-defined-literals.cpp
new file mode 100644
index 0000000..e77e807
--- /dev/null
+++ b/test/SemaCXX/cxx11-user-defined-literals.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s -fms-extensions -triple x86_64-apple-darwin9.0.0
+
+using size_t = decltype(sizeof(int));
+enum class LitKind {
+  Char, WideChar, Char16, Char32,
+  CharStr, WideStr, Char16Str, Char32Str,
+  Integer, Floating
+};
+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; }
+constexpr LitKind operator"" _kind(unsigned long long n) { return LitKind::Integer; }
+constexpr LitKind operator"" _kind(long double n) { return LitKind::Floating; }
+
+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, "");
+static_assert(194_kind == LitKind::Integer, "");
+static_assert(0377_kind == LitKind::Integer, "");
+static_assert(0x5ffc_kind == LitKind::Integer, "");
+static_assert(.5954_kind == LitKind::Floating, "");
+static_assert(1._kind == LitKind::Floating, "");
+static_assert(1.e-2_kind == LitKind::Floating, "");
+static_assert(4e6_kind == LitKind::Floating, "");