diff options
Diffstat (limited to 'test/SemaCXX')
-rw-r--r-- | test/SemaCXX/constant-expression-cxx11.cpp | 8 | ||||
-rw-r--r-- | test/SemaCXX/constant-expression-cxx1y.cpp | 119 | ||||
-rw-r--r-- | test/SemaCXX/enum-unscoped-nonexistent.cpp | 4 | ||||
-rw-r--r-- | test/SemaCXX/ms-wchar.cpp | 3 | ||||
-rw-r--r-- | test/SemaCXX/nested-name-spec.cpp | 10 | ||||
-rw-r--r-- | test/SemaCXX/string-init.cpp | 40 |
6 files changed, 180 insertions, 4 deletions
diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp index 09a9cb5dd8..97b0b91b99 100644 --- a/test/SemaCXX/constant-expression-cxx11.cpp +++ b/test/SemaCXX/constant-expression-cxx11.cpp @@ -1503,3 +1503,11 @@ namespace PR15884 { // expected-note@-3 {{pointer to temporary is not a constant expression}} // expected-note@-4 {{temporary created here}} } + +namespace AfterError { + // FIXME: Suppress the 'no return statements' diagnostic if the body is invalid. + constexpr int error() { // expected-error {{no return statement}} + return foobar; // expected-error {{undeclared identifier}} + } + constexpr int k = error(); // expected-error {{must be initialized by a constant expression}} +} diff --git a/test/SemaCXX/constant-expression-cxx1y.cpp b/test/SemaCXX/constant-expression-cxx1y.cpp index 824a0e8b91..ea0c9e6526 100644 --- a/test/SemaCXX/constant-expression-cxx1y.cpp +++ b/test/SemaCXX/constant-expression-cxx1y.cpp @@ -250,11 +250,12 @@ namespace lifetime { } namespace const_modify { - constexpr int modify(int &n) { return n = 1; } // expected-note {{modification of object of const-qualified type 'const int'}} + constexpr int modify(int &n) { return n = 1; } // expected-note 2 {{modification of object of const-qualified type 'const int'}} constexpr int test1() { int k = 0; return modify(k); } - constexpr int test2() { const int k = 0; return modify(const_cast<int&>(k)); } // expected-note {{in call}} + constexpr int test2() { const int k = 0; return modify(const_cast<int&>(k)); } // expected-note 2 {{in call}} static_assert(test1() == 1, ""); static_assert(test2() == 1, ""); // expected-error {{constant expression}} expected-note {{in call}} + constexpr int i = test2(); // expected-error {{constant expression}} expected-note {{in call}} } namespace null { @@ -593,3 +594,117 @@ namespace assignment_op { } static_assert(testC(), ""); } + +namespace switch_stmt { + constexpr int f(char k) { + bool b = false; + int z = 6; + switch (k) { + return -1; + case 0: + if (false) { + case 1: + z = 1; + for (; b;) { + return 5; + while (0) + case 2: return 2; + case 7: z = 7; + do case 6: { + return z; + if (false) + case 3: return 3; + case 4: z = 4; + } while (1); + case 5: b = true; + case 9: z = 9; + } + return z; + } else if (false) case 8: z = 8; + else if (false) { + case 10: + z = -10; + break; + } + else z = 0; + return z; + default: + return -1; + } + return -z; + } + static_assert(f(0) == 0, ""); + static_assert(f(1) == 1, ""); + static_assert(f(2) == 2, ""); + static_assert(f(3) == 3, ""); + static_assert(f(4) == 4, ""); + static_assert(f(5) == 5, ""); + static_assert(f(6) == 6, ""); + static_assert(f(7) == 7, ""); + static_assert(f(8) == 8, ""); + static_assert(f(9) == 9, ""); + static_assert(f(10) == 10, ""); + + // Check that we can continue an outer loop from within a switch. + constexpr bool contin() { + for (int n = 0; n != 10; ++n) { + switch (n) { + case 0: + ++n; + continue; + case 1: + return false; + case 2: + return true; + } + } + return false; + } + static_assert(contin(), ""); + + constexpr bool switch_into_for() { + int n = 0; + switch (n) { + for (; n == 1; ++n) { + return n == 1; + case 0: ; + } + } + return false; + } + static_assert(switch_into_for(), ""); + + constexpr void duff_copy(char *a, const char *b, int n) { + switch ((n - 1) % 8 + 1) { + for ( ; n; n = (n - 1) & ~7) { + case 8: a[n-8] = b[n-8]; + case 7: a[n-7] = b[n-7]; + case 6: a[n-6] = b[n-6]; + case 5: a[n-5] = b[n-5]; + case 4: a[n-4] = b[n-4]; + case 3: a[n-3] = b[n-3]; + case 2: a[n-2] = b[n-2]; + case 1: a[n-1] = b[n-1]; + } + case 0: ; + } + } + + constexpr bool test_copy(const char *str, int n) { + char buffer[16] = {}; + duff_copy(buffer, str, n); + for (int i = 0; i != sizeof(buffer); ++i) + if (buffer[i] != (i < n ? str[i] : 0)) + return false; + return true; + } + static_assert(test_copy("foo", 0), ""); + static_assert(test_copy("foo", 1), ""); + static_assert(test_copy("foo", 2), ""); + static_assert(test_copy("hello world", 0), ""); + static_assert(test_copy("hello world", 7), ""); + static_assert(test_copy("hello world", 8), ""); + static_assert(test_copy("hello world", 9), ""); + static_assert(test_copy("hello world", 10), ""); + static_assert(test_copy("hello world", 10), ""); +} diff --git a/test/SemaCXX/enum-unscoped-nonexistent.cpp b/test/SemaCXX/enum-unscoped-nonexistent.cpp index e9da38f558..7da9a96d60 100644 --- a/test/SemaCXX/enum-unscoped-nonexistent.cpp +++ b/test/SemaCXX/enum-unscoped-nonexistent.cpp @@ -6,7 +6,7 @@ struct Base { template<typename T> struct S : Base { enum E : int; constexpr int f() const; - constexpr int g() const; // expected-note {{declared here}} + constexpr int g() const; void h(); }; template<> enum S<char>::E : int {}; // expected-note {{enum 'S<char>::E' was explicitly specialized here}} @@ -23,7 +23,7 @@ static_assert(S<int>().f() == 1, ""); // The unqualified-id here names a member of the current instantiation, which // bizarrely might not exist in some instantiations. template<typename T> constexpr int S<T>::g() const { return b; } // expected-error {{enumerator 'b' does not exist in instantiation of 'S<char>'}} -static_assert(S<char>().g() == 1, ""); // expected-note {{here}} expected-error {{not an integral constant expression}} expected-note {{undefined}} +static_assert(S<char>().g() == 1, ""); // expected-note {{here}} expected-error {{not an integral constant expression}} static_assert(S<short>().g() == 2, ""); static_assert(S<long>().g() == 8, ""); diff --git a/test/SemaCXX/ms-wchar.cpp b/test/SemaCXX/ms-wchar.cpp index 2cbf745d33..878d8cadce 100644 --- a/test/SemaCXX/ms-wchar.cpp +++ b/test/SemaCXX/ms-wchar.cpp @@ -7,3 +7,6 @@ __wchar_t g = L'a'; __wchar_t s[] = L"Hello world!"; unsigned short t[] = L"Hello world!"; // expected-error{{array initializer must be an initializer list}} + +wchar_t u[] = 1; // expected-error{{array initializer must be an initializer list or wide string literal}} +__wchar_t v[] = 1; // expected-error{{array initializer must be an initializer list or wide string literal}} diff --git a/test/SemaCXX/nested-name-spec.cpp b/test/SemaCXX/nested-name-spec.cpp index 7239646d8d..228bc0ecbd 100644 --- a/test/SemaCXX/nested-name-spec.cpp +++ b/test/SemaCXX/nested-name-spec.cpp @@ -297,3 +297,13 @@ namespace NS { int foobar = a + longer_b; // expected-error {{use of undeclared identifier 'a'; did you mean 'NS::a'?}} \ // expected-error {{use of undeclared identifier 'longer_b'; did you mean 'NS::longer_b'?}} } + +// <rdar://problem/13853540> +namespace N { + struct X { }; + namespace N { + struct Foo { + struct N::X *foo(); // expected-error{{no struct named 'X' in namespace 'N::N'}} + }; + } +} diff --git a/test/SemaCXX/string-init.cpp b/test/SemaCXX/string-init.cpp new file mode 100644 index 0000000000..7e62d1855a --- /dev/null +++ b/test/SemaCXX/string-init.cpp @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s + +void f() { + char a1[] = "a"; // No error. + char a2[] = u8"a"; // No error. + char a3[] = u"a"; // expected-error{{initializing char array with wide string literal}} + char a4[] = U"a"; // expected-error{{initializing char array with wide string literal}} + char a5[] = L"a"; // expected-error{{initializing char array with wide string literal}} + + wchar_t b1[] = "a"; // expected-error{{initializing wide char array with non-wide string literal}} + wchar_t b2[] = u8"a"; // expected-error{{initializing wide char array with non-wide string literal}} + wchar_t b3[] = u"a"; // expected-error{{initializing wide char array with incompatible wide string literal}} + wchar_t b4[] = U"a"; // expected-error{{initializing wide char array with incompatible wide string literal}} + wchar_t b5[] = L"a"; // No error. + + char16_t c1[] = "a"; // expected-error{{initializing wide char array with non-wide string literal}} + char16_t c2[] = u8"a"; // expected-error{{initializing wide char array with non-wide string literal}} + char16_t c3[] = u"a"; // No error. + char16_t c4[] = U"a"; // expected-error{{initializing wide char array with incompatible wide string literal}} + char16_t c5[] = L"a"; // expected-error{{initializing wide char array with incompatible wide string literal}} + + char32_t d1[] = "a"; // expected-error{{initializing wide char array with non-wide string literal}} + char32_t d2[] = u8"a"; // expected-error{{initializing wide char array with non-wide string literal}} + char32_t d3[] = u"a"; // expected-error{{initializing wide char array with incompatible wide string literal}} + char32_t d4[] = U"a"; // No error. + char32_t d5[] = L"a"; // expected-error{{initializing wide char array with incompatible wide string literal}} + + int e1[] = "a"; // expected-error{{array initializer must be an initializer list}} + int e2[] = u8"a"; // expected-error{{array initializer must be an initializer list}} + int e3[] = u"a"; // expected-error{{array initializer must be an initializer list}} + int e4[] = U"a"; // expected-error{{array initializer must be an initializer list}} + int e5[] = L"a"; // expected-error{{array initializer must be an initializer list}} +} + +void g() { + char a[] = 1; // expected-error{{array initializer must be an initializer list or string literal}} + wchar_t b[] = 1; // expected-error{{array initializer must be an initializer list or wide string literal}} + char16_t c[] = 1; // expected-error{{array initializer must be an initializer list or wide string literal}} + char32_t d[] = 1; // expected-error{{array initializer must be an initializer list or wide string literal}} +} |