summaryrefslogtreecommitdiffstats
path: root/test/CXX
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-03-09 22:27:51 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-03-09 22:27:51 +0000
commit26b75c07317a3b50a8a00a1623e3ef38af1d8349 (patch)
tree7a996e959bd9bb606c4374000762a9118a92168c /test/CXX
parente7d6ca079a68ed9ea7fa6e5d6bfc9f625a37df76 (diff)
Improve diagnostics for UCNs referring to control characters and members of the
basic source character set in C++98. Add -Wc++98-compat diagnostics for same in literals in C++11. Extend such support to cover string literals as well as character literals, and mark N2170 as done. This seems too minor to warrant a release note to me. Let me know if you disagree. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152444 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX')
-rw-r--r--test/CXX/lex/lex.charset/p2-cxx11.cpp42
-rw-r--r--test/CXX/lex/lex.charset/p2-cxx98.cpp55
2 files changed, 97 insertions, 0 deletions
diff --git a/test/CXX/lex/lex.charset/p2-cxx11.cpp b/test/CXX/lex/lex.charset/p2-cxx11.cpp
new file mode 100644
index 0000000000..b9192cebe6
--- /dev/null
+++ b/test/CXX/lex/lex.charset/p2-cxx11.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -verify -std=c++11 %s
+
+char c00 = '\u0000'; // ok
+char c01 = '\u0001'; // ok
+char c1f = '\u001f'; // ok
+char c20 = '\u0020'; // ' ', ok
+char c22 = '\u0022'; // ", ok
+char c23 = '\u0023'; // #, ok
+char c24 = '\u0024'; // $, ok
+char c25 = '\u0025'; // %, ok
+char c27 = '\u0027'; // ', ok
+char c3f = '\u003f'; // ?, ok
+char c40 = '\u0040'; // @, ok
+char c41 = '\u0041'; // A, ok
+char c5f = '\u005f'; // _, ok
+char c60 = '\u0060'; // `, ok
+char c7e = '\u007e'; // ~, ok
+char c7f = '\u007f'; // ok
+
+wchar_t w007f = L'\u007f';
+wchar_t w0080 = L'\u0080';
+wchar_t w009f = L'\u009f';
+wchar_t w00a0 = L'\u00a0';
+
+wchar_t wd799 = L'\ud799';
+wchar_t wd800 = L'\ud800'; // expected-error {{invalid universal character}}
+wchar_t wdfff = L'\udfff'; // expected-error {{invalid universal character}}
+wchar_t we000 = L'\ue000';
+
+char32_t w10fffe = U'\U0010fffe';
+char32_t w10ffff = U'\U0010ffff';
+char32_t w110000 = U'\U00110000'; // expected-error {{invalid universal character}}
+
+const char *p1 = "\u0000\u0001\u001f\u0020\u0022\u0023\u0024\u0025\u0027\u003f\u0040\u0041\u005f\u0060\u007e\u007f";
+const wchar_t *p2 = L"\u0000\u0012\u004e\u007f\u0080\u009f\u00a0\ud799\ue000";
+const char *p3 = u8"\u0000\u0012\u004e\u007f\u0080\u009f\u00a0\ud799\ue000";
+const char16_t *p4 = u"\u0000\u0012\u004e\u007f\u0080\u009f\u00a0\ud799\ue000";
+const char32_t *p5 = U"\u0000\u0012\u004e\u007f\u0080\u009f\u00a0\ud799\ue000";
+const wchar_t *p6 = L"foo \U00110000 bar"; // expected-error {{invalid universal character}}
+const char *p7 = u8"foo \U0000d800 bar"; // expected-error {{invalid universal character}}
+const char16_t *p8 = u"foo \U0000dfff bar"; // expected-error {{invalid universal character}}
+const char32_t *p9 = U"foo \U0010ffff bar"; // ok
diff --git a/test/CXX/lex/lex.charset/p2-cxx98.cpp b/test/CXX/lex/lex.charset/p2-cxx98.cpp
new file mode 100644
index 0000000000..a5b7ab6488
--- /dev/null
+++ b/test/CXX/lex/lex.charset/p2-cxx98.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -verify -std=c++98 %s
+
+char c00 = '\u0000'; // expected-error {{universal character name refers to a control character}}
+char c01 = '\u0001'; // expected-error {{universal character name refers to a control character}}
+char c1f = '\u001f'; // expected-error {{universal character name refers to a control character}}
+char c20 = '\u0020'; // ' ', expected-error {{character ' ' cannot be specified by a universal character name}}
+char c22 = '\u0022'; // ", expected-error {{character '"' cannot be specified by a universal character name}}
+char c23 = '\u0023'; // #, expected-error {{character '#' cannot be specified by a universal character name}}
+char c24 = '\u0024'; // $, ok
+char c25 = '\u0025'; // %, expected-error {{character '%' cannot be specified by a universal character name}}
+char c27 = '\u0027'; // ', expected-error {{character ''' cannot be specified by a universal character name}}
+char c3f = '\u003f'; // ?, expected-error {{character '?' cannot be specified by a universal character name}}
+char c40 = '\u0040'; // @, ok
+char c41 = '\u0041'; // A, expected-error {{character 'A' cannot be specified by a universal character name}}
+char c5f = '\u005f'; // _, expected-error {{character '_' cannot be specified by a universal character name}}
+char c60 = '\u0060'; // `, ok
+char c7e = '\u007e'; // ~, expected-error {{character '~' cannot be specified by a universal character name}}
+char c7f = '\u007f'; // expected-error {{universal character name refers to a control character}}
+
+wchar_t w007f = L'\u007f'; // expected-error {{universal character name refers to a control character}}
+wchar_t w0080 = L'\u0080'; // expected-error {{universal character name refers to a control character}}
+wchar_t w009f = L'\u009f'; // expected-error {{universal character name refers to a control character}}
+wchar_t w00a0 = L'\u00a0';
+
+wchar_t wd799 = L'\ud799';
+wchar_t wd800 = L'\ud800'; // expected-error {{invalid universal character}}
+wchar_t wdfff = L'\udfff'; // expected-error {{invalid universal character}}
+wchar_t we000 = L'\ue000';
+
+const char *s00 = "\u0000"; // expected-error {{universal character name refers to a control character}}
+const char *s01 = "\u0001"; // expected-error {{universal character name refers to a control character}}
+const char *s1f = "\u001f"; // expected-error {{universal character name refers to a control character}}
+const char *s20 = "\u0020"; // ' ', expected-error {{character ' ' cannot be specified by a universal character name}}
+const char *s22 = "\u0022"; // ", expected-error {{character '"' cannot be specified by a universal character name}}
+const char *s23 = "\u0023"; // #, expected-error {{character '#' cannot be specified by a universal character name}}
+const char *s24 = "\u0024"; // $, ok
+const char *s25 = "\u0025"; // %, expected-error {{character '%' cannot be specified by a universal character name}}
+const char *s27 = "\u0027"; // ', expected-error {{character ''' cannot be specified by a universal character name}}
+const char *s3f = "\u003f"; // ?, expected-error {{character '?' cannot be specified by a universal character name}}
+const char *s40 = "\u0040"; // @, ok
+const char *s41 = "\u0041"; // A, expected-error {{character 'A' cannot be specified by a universal character name}}
+const char *s5f = "\u005f"; // _, expected-error {{character '_' cannot be specified by a universal character name}}
+const char *s60 = "\u0060"; // `, ok
+const char *s7e = "\u007e"; // ~, expected-error {{character '~' cannot be specified by a universal character name}}
+const char *s7f = "\u007f"; // expected-error {{universal character name refers to a control character}}
+
+const wchar_t *ws007f = L"\u007f"; // expected-error {{universal character name refers to a control character}}
+const wchar_t *ws0080 = L"\u0080"; // expected-error {{universal character name refers to a control character}}
+const wchar_t *ws009f = L"\u009f"; // expected-error {{universal character name refers to a control character}}
+const wchar_t *ws00a0 = L"\u00a0";
+
+const wchar_t *wsd799 = L"\ud799";
+const wchar_t *wsd800 = L"\ud800"; // expected-error {{invalid universal character}}
+const wchar_t *wsdfff = L"\udfff"; // expected-error {{invalid universal character}}
+const wchar_t *wse000 = L"\ue000";