summaryrefslogtreecommitdiff
path: root/test/CXX/lex
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-03-09 08:00:36 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-03-09 08:00:36 +0000
commit36f5cfe4df32af6c5fe01228102512996f566f9d (patch)
tree28e2c2562f781f6dbe711d15a00af596b21b9c9b /test/CXX/lex
parent8a26fc15d4647da863f0cca73a203823b01da7e5 (diff)
downloadclang-36f5cfe4df32af6c5fe01228102512996f566f9d.tar.gz
Support for raw and template forms of numeric user-defined literals,
and lots of tidying up. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152392 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX/lex')
-rw-r--r--test/CXX/lex/lex.literal/lex.ext/p2.cpp16
-rw-r--r--test/CXX/lex/lex.literal/lex.ext/p3.cpp18
-rw-r--r--test/CXX/lex/lex.literal/lex.ext/p4.cpp18
-rw-r--r--test/CXX/lex/lex.literal/lex.ext/p5.cpp13
-rw-r--r--test/CXX/lex/lex.literal/lex.ext/p6.cpp14
-rw-r--r--test/CXX/lex/lex.literal/lex.ext/p7.cpp27
6 files changed, 106 insertions, 0 deletions
diff --git a/test/CXX/lex/lex.literal/lex.ext/p2.cpp b/test/CXX/lex/lex.literal/lex.ext/p2.cpp
new file mode 100644
index 0000000000..aa7393cffb
--- /dev/null
+++ b/test/CXX/lex/lex.literal/lex.ext/p2.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+
+typedef decltype(sizeof(int)) size_t;
+
+// FIXME: These diagnostics should say 'size_t' instead of 'unsigned long'
+int a = 123_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'unsigned long long' or 'const char *', and no matching literal operator template}}
+int b = 4.2_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'long double' or 'const char *', and no matching literal operator template}}
+int c = "foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const char *' and 'unsigned long'}}
+int d = L"foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const wchar_t *' and 'unsigned long'}}
+int e = u8"foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const char *' and 'unsigned long'}}
+int f = u"foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const char16_t *' and 'unsigned long'}}
+int g = U"foo"_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with arguments of types 'const char32_t *' and 'unsigned long'}}
+int h = 'y'_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'char'}}
+int i = L'y'_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'wchar_t'}}
+int j = u'y'_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'char16_t'}}
+int k = U'y'_x; // expected-error {{no matching literal operator for call to 'operator "" _x' with argument of type 'char32_t'}}
diff --git a/test/CXX/lex/lex.literal/lex.ext/p3.cpp b/test/CXX/lex/lex.literal/lex.ext/p3.cpp
new file mode 100644
index 0000000000..43f3468e96
--- /dev/null
+++ b/test/CXX/lex/lex.literal/lex.ext/p3.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+
+int &operator "" _x1 (unsigned long long);
+int &i1 = 0x123_x1;
+
+double &operator "" _x1 (const char *);
+int &i2 = 45_x1;
+
+template<char...> char &operator "" _x1 ();
+int &i3 = 0377_x1;
+
+int &i4 = 90000000000000000000000000000000000000000000000_x1; // expected-warning {{integer constant is too large}}
+
+double &operator "" _x2 (const char *);
+double &i5 = 123123123123123123123123123123123123123123123_x2;
+
+template<char...Cs> constexpr int operator "" _x3() { return sizeof...(Cs); }
+static_assert(123456789012345678901234567890123456789012345678901234567890_x3 == 60, "");
diff --git a/test/CXX/lex/lex.literal/lex.ext/p4.cpp b/test/CXX/lex/lex.literal/lex.ext/p4.cpp
new file mode 100644
index 0000000000..011e832c69
--- /dev/null
+++ b/test/CXX/lex/lex.literal/lex.ext/p4.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+
+int &operator "" _x1 (long double);
+int &i1 = 0.123_x1;
+
+double &operator "" _x1 (const char *);
+int &i2 = 45._x1;
+
+template<char...> char &operator "" _x1 ();
+int &i3 = 0377e-1_x1;
+
+int &i4 = 1e1000000_x1; // expected-warning {{too large for type 'long double'}}
+
+double &operator "" _x2 (const char *);
+double &i5 = 1e1000000_x2;
+
+template<char...Cs> constexpr int operator "" _x3() { return sizeof...(Cs); }
+static_assert(1e1000000_x3 == 9, "");
diff --git a/test/CXX/lex/lex.literal/lex.ext/p5.cpp b/test/CXX/lex/lex.literal/lex.ext/p5.cpp
new file mode 100644
index 0000000000..4655aa17dc
--- /dev/null
+++ b/test/CXX/lex/lex.literal/lex.ext/p5.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+
+using size_t = decltype(sizeof(int));
+
+int &operator "" _x1 (const char *);
+double &operator "" _x1 (const char *, size_t);
+double &i1 = "foo"_x1;
+double &i2 = u8"foo"_x1;
+double &i3 = L"foo"_x1; // expected-error {{no matching literal operator}}
+
+char &operator "" _x1(const wchar_t *, size_t);
+char &i4 = L"foo"_x1; // ok
+double &i5 = R"(foo)"_x1; // ok
diff --git a/test/CXX/lex/lex.literal/lex.ext/p6.cpp b/test/CXX/lex/lex.literal/lex.ext/p6.cpp
new file mode 100644
index 0000000000..23cd7081d5
--- /dev/null
+++ b/test/CXX/lex/lex.literal/lex.ext/p6.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+
+using size_t = decltype(sizeof(int));
+
+int &operator "" _x1 (const char *);
+double &i1 = 'a'_x1; // expected-error {{no matching literal operator}}
+double &operator "" _x1 (wchar_t);
+double &i2 = L'a'_x1;
+double &i3 = 'a'_x1; // expected-error {{no matching literal operator}}
+double &i4 = operator"" _x1('a'); // ok
+
+char &operator "" _x1(char16_t);
+char &i5 = u'a'_x1; // ok
+double &i6 = L'a'_x1; // ok
diff --git a/test/CXX/lex/lex.literal/lex.ext/p7.cpp b/test/CXX/lex/lex.literal/lex.ext/p7.cpp
new file mode 100644
index 0000000000..79c9394a96
--- /dev/null
+++ b/test/CXX/lex/lex.literal/lex.ext/p7.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+
+using size_t = decltype(sizeof(int));
+namespace std {
+ struct string {};
+}
+
+template<typename T, typename U> struct same_type;
+template<typename T> struct same_type<T, T> {};
+
+namespace std_example {
+
+long double operator "" _w(long double);
+std::string operator "" _w(const char16_t*, size_t);
+unsigned operator "" _w(const char*);
+int main() {
+ auto v1 = 1.2_w; // calls operator "" _w(1.2L)
+ auto v2 = u"one"_w; // calls operator "" _w(u"one", 3)
+ auto v3 = 12_w; // calls operator "" _w("12")
+ "two"_w; // expected-error {{no matching literal operator}}
+
+ same_type<decltype(v1), long double> test1;
+ same_type<decltype(v2), std::string> test2;
+ same_type<decltype(v3), unsigned> test3;
+}
+
+}