summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/SemaCXX')
-rw-r--r--clang/test/SemaCXX/constant-expression-cxx2a.cpp119
-rw-r--r--clang/test/SemaCXX/constexpr-many-arguments.cpp4
-rw-r--r--clang/test/SemaCXX/shift.cpp5
3 files changed, 7 insertions, 121 deletions
diff --git a/clang/test/SemaCXX/constant-expression-cxx2a.cpp b/clang/test/SemaCXX/constant-expression-cxx2a.cpp
index dba877ff211..cc6b1960481 100644
--- a/clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ b/clang/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__;
diff --git a/clang/test/SemaCXX/constexpr-many-arguments.cpp b/clang/test/SemaCXX/constexpr-many-arguments.cpp
index 3b5e974b332..e5bc1ec66c5 100644
--- a/clang/test/SemaCXX/constexpr-many-arguments.cpp
+++ b/clang/test/SemaCXX/constexpr-many-arguments.cpp
@@ -12,7 +12,7 @@ struct type2
typedef type1 T;
constexpr type2(T a00, T a01, T a02, T a03, T a04, T a05, T a06, T a07, T a08, T a09,
T a10, T a11, T a12, T a13, T a14, T a15, T a16, T a17, T a18, T a19,
- T a20, T a21, T a22)
+ T a20, T a21, T a22)
: my_data{a00, a01, a02, a03, a04, a05, a06, a07, a08, a09,
a10, a11, a12, a13, a14, a15, a16, a17, a18, a19,
a20, a21, a22}
@@ -32,7 +32,7 @@ constexpr type3 g
{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
{0},{0},{0}
- },
+ },
{
{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
diff --git a/clang/test/SemaCXX/shift.cpp b/clang/test/SemaCXX/shift.cpp
index f99b53e358a..6c5f1c1913e 100644
--- a/clang/test/SemaCXX/shift.cpp
+++ b/clang/test/SemaCXX/shift.cpp
@@ -82,3 +82,8 @@ void vect_shift_2(vec16 *x, vec16 y) { *x = *x << y; }
void vect_shift_3(vec16 *x, vec8 y) {
*x = *x << y; // expected-error {{vector operands do not have the same number of elements}}
}
+static_assert(-1 >> 1 == -1);
+static_assert(-1 >> 31 == -1);
+static_assert(-2 >> 1 == -1);
+static_assert(-3 >> 1 == -2);
+static_assert(-4 >> 1 == -2);
OpenPOWER on IntegriCloud