diff options
Diffstat (limited to 'clang/test/AST/ByteCode')
| -rw-r--r-- | clang/test/AST/ByteCode/bitfields.cpp | 79 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/builtin-functions.cpp | 13 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/cxx14.cpp | 9 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/records.cpp | 21 |
4 files changed, 122 insertions, 0 deletions
diff --git a/clang/test/AST/ByteCode/bitfields.cpp b/clang/test/AST/ByteCode/bitfields.cpp index df8d567..a583282 100644 --- a/clang/test/AST/ByteCode/bitfields.cpp +++ b/clang/test/AST/ByteCode/bitfields.cpp @@ -128,3 +128,82 @@ namespace NonConstBitWidth { // both-note {{read of non-const variable}} }; } + +namespace IncDecOverflow { + constexpr bool test1() { + struct {unsigned u: 5; } a {}; + a.u--; + return a.u == 31; + } + static_assert(test1(), ""); + + constexpr bool test2() { + struct {unsigned u: 5; } a {}; + --a.u; + return a.u == 31; + } + static_assert(test2(), ""); + + constexpr bool test3() { + int x = 0; + struct {unsigned u: 5; } a {}; + x = a.u--; + return a.u == 31; + } + static_assert(test3(), ""); + + constexpr bool test4() { + int x = 0; + struct {unsigned u: 5; } a {}; + x = --a.u; + return a.u == 31; + } + static_assert(test4(), ""); + + constexpr bool test5() { + struct {unsigned u: 5; } a {}; + a.u = 31; + ++a.u; + + return a.u == 0; + } + static_assert(test5(), ""); + + constexpr bool test6() { + struct {unsigned u: 5; } a {}; + a.u = 31; + ++a.u; + + return a.u == 0; + } + static_assert(test6(), ""); + + constexpr bool test7() { + struct {unsigned u: 5; } a {}; + a.u = 31; + a.u++; + + return a.u == 0; + } + static_assert(test7(), ""); + + constexpr bool test8() { + int x = 0; + struct {unsigned u: 5; } a {}; + a.u = 31; + x = a.u++; + + return a.u == 0; + } + static_assert(test8(), ""); + + constexpr bool test9() { + int x = 0; + struct {unsigned u: 5; } a {}; + a.u = 31; + x = ++a.u; + + return a.u == 0; + } + static_assert(test9(), ""); +} diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp index f47bc49..0b7d51b 100644 --- a/clang/test/AST/ByteCode/builtin-functions.cpp +++ b/clang/test/AST/ByteCode/builtin-functions.cpp @@ -63,6 +63,19 @@ constexpr int test_address_of_incomplete_array_type() { // both-error {{never pr static_assert(test_address_of_incomplete_array_type() == 1234, ""); // both-error {{constant}} \ // both-note {{in call}} +namespace LocalExternRedecl { + constexpr int externRedecl1() { + extern int arr[]; + return 0; + } + constexpr int externRedecl2() { // both-error {{never produces a constant expression}} + extern int arr[]; + __builtin_memmove(&arr, &arr, 4 * sizeof(arr[0])); // both-note 2{{incomplete type}} + return 1234; + } + static_assert(externRedecl2() == 1234); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} +} struct NonTrivial { constexpr NonTrivial() : n(0) {} diff --git a/clang/test/AST/ByteCode/cxx14.cpp b/clang/test/AST/ByteCode/cxx14.cpp new file mode 100644 index 0000000..9622311 --- /dev/null +++ b/clang/test/AST/ByteCode/cxx14.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -std=c++14 -verify=both,expected %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -std=c++14 -verify=both,ref %s + + + +constexpr int(*null_ptr)() = nullptr; +constexpr int test4 = (*null_ptr)(); // both-error {{must be initialized by a constant expression}} \ + // both-note {{evaluates to a null function pointer}} + diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp index 48cf811..00218ba 100644 --- a/clang/test/AST/ByteCode/records.cpp +++ b/clang/test/AST/ByteCode/records.cpp @@ -1162,6 +1162,19 @@ namespace IndirectFieldInit { static_assert(s2.x == 1 && s2.y == 2 && s2.a == 3 && s2.b == 4); #endif + + + struct B { + struct { + union { + int x = 3; + }; + int y = this->x; + }; + + constexpr B() {} + }; + static_assert(B().y == 3, ""); } namespace InheritedConstructor { @@ -1840,3 +1853,11 @@ namespace DiamondDowncast { constexpr Middle2 &fail = (Middle2&)top1; // both-error {{must be initialized by a constant expression}} \ // both-note {{cannot cast object of dynamic type 'const Bottom' to type 'Middle2'}} } + +namespace PrimitiveInitializedByInitList { + constexpr struct { + int a; + int b{this->a}; + } c{ 17 }; + static_assert(c.b == 17, ""); +} |
