summaryrefslogtreecommitdiff
path: root/test/SemaCXX/constant-expression-cxx2a.cpp
diff options
context:
space:
mode:
authorNandor Licker <n@ndor.email>2019-09-04 05:49:41 +0000
committerNandor Licker <n@ndor.email>2019-09-04 05:49:41 +0000
commitc0da99ee6c41d7ac4ed7919865dd17f71babb764 (patch)
tree1c740ef679431a247fc42cc675f5514a0f320531 /test/SemaCXX/constant-expression-cxx2a.cpp
parentcb57fe36feaa1b01253a354795b728f503aac39c (diff)
downloadclang-c0da99ee6c41d7ac4ed7919865dd17f71babb764.tar.gz
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary: This patch introduces the skeleton of the constexpr interpreter, capable of evaluating a simple constexpr functions consisting of if statements. The interpreter is described in more detail in the RFC. Further patches will add more features. Reviewers: Bigcheese, jfb, rsmith Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64146 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370839 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/constant-expression-cxx2a.cpp')
-rw-r--r--test/SemaCXX/constant-expression-cxx2a.cpp119
1 files changed, 0 insertions, 119 deletions
diff --git a/test/SemaCXX/constant-expression-cxx2a.cpp b/test/SemaCXX/constant-expression-cxx2a.cpp
index dba877ff21..cc6b196048 100644
--- a/test/SemaCXX/constant-expression-cxx2a.cpp
+++ b/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -414,125 +414,6 @@ namespace TypeId {
static_assert(side_effects());
}
-namespace Union {
- struct Base {
- int y; // expected-note {{here}}
- };
- struct A : Base {
- int x;
- int arr[3];
- union { int p, q; };
- };
- union B {
- A a;
- int b;
- };
- constexpr int read_wrong_member() { // expected-error {{never produces a constant}}
- B b = {.b = 1};
- return b.a.x; // expected-note {{read of member 'a' of union with active member 'b'}}
- }
- constexpr int change_member() {
- B b = {.b = 1};
- b.a.x = 1;
- return b.a.x;
- }
- static_assert(change_member() == 1);
- constexpr int change_member_then_read_wrong_member() { // expected-error {{never produces a constant}}
- B b = {.b = 1};
- b.a.x = 1;
- return b.b; // expected-note {{read of member 'b' of union with active member 'a'}}
- }
- constexpr int read_wrong_member_indirect() { // expected-error {{never produces a constant}}
- B b = {.b = 1};
- int *p = &b.a.y;
- return *p; // expected-note {{read of member 'a' of union with active member 'b'}}
- }
- constexpr int read_uninitialized() {
- B b = {.b = 1};
- int *p = &b.a.y;
- b.a.x = 1;
- return *p; // expected-note {{read of uninitialized object}}
- }
- static_assert(read_uninitialized() == 0); // expected-error {{constant}} expected-note {{in call}}
- constexpr void write_wrong_member_indirect() { // expected-error {{never produces a constant}}
- B b = {.b = 1};
- int *p = &b.a.y;
- *p = 1; // expected-note {{assignment to member 'a' of union with active member 'b'}}
- }
- constexpr int write_uninitialized() {
- B b = {.b = 1};
- int *p = &b.a.y;
- b.a.x = 1;
- *p = 1;
- return *p;
- }
- static_assert(write_uninitialized() == 1);
- constexpr int change_member_indirectly() {
- B b = {.b = 1};
- b.a.arr[1] = 1;
- int &r = b.a.y;
- r = 123;
-
- b.b = 2;
- b.a.y = 3;
- b.a.arr[2] = 4;
- return b.a.arr[2];
- }
- static_assert(change_member_indirectly() == 4);
- constexpr B return_uninit() {
- B b = {.b = 1};
- b.a.x = 2;
- return b;
- }
- constexpr B uninit = return_uninit(); // expected-error {{constant expression}} expected-note {{subobject of type 'int' is not initialized}}
- static_assert(return_uninit().a.x == 2);
- constexpr A return_uninit_struct() {
- B b = {.b = 1};
- b.a.x = 2;
- return b.a;
- }
- // FIXME: It's unclear that this should be valid. Copying a B involves
- // copying the object representation of the union, but copying an A invokes a
- // copy constructor that copies the object elementwise, and reading from
- // b.a.y is undefined.
- static_assert(return_uninit_struct().x == 2);
- constexpr B return_init_all() {
- B b = {.b = 1};
- b.a.x = 2;
- b.a.y = 3;
- b.a.arr[0] = 4;
- b.a.arr[1] = 5;
- b.a.arr[2] = 6;
- return b;
- }
- static_assert(return_init_all().a.x == 2);
- static_assert(return_init_all().a.y == 3);
- static_assert(return_init_all().a.arr[0] == 4);
- static_assert(return_init_all().a.arr[1] == 5);
- static_assert(return_init_all().a.arr[2] == 6);
- static_assert(return_init_all().a.p == 7); // expected-error {{}} expected-note {{read of member 'p' of union with no active member}}
- static_assert(return_init_all().a.q == 8); // expected-error {{}} expected-note {{read of member 'q' of union with no active member}}
- constexpr B init_all = return_init_all();
-
- constexpr bool test_no_member_change = []{
- union U { char dummy = {}; };
- U u1;
- U u2;
- u1 = u2;
- return true;
- }();
-
- struct S1 {
- int n;
- };
- struct S2 : S1 {};
- struct S3 : S2 {};
- void f() {
- S3 s;
- s.n = 0;
- }
-}
-
namespace TwosComplementShifts {
using uint32 = __UINT32_TYPE__;
using int32 = __INT32_TYPE__;