Skip to content

Commit

Permalink
[clang][Interp][NFC] Add more _Complex tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Mar 14, 2024
1 parent a551cce commit 2421e76
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions clang/test/AST/Interp/complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,53 @@ namespace Cmp {
static_assert((0.0 + 0.0j) > (0.0 + 0.0j)); // both-error {{invalid operands to binary expression}}
static_assert((0.0 + 0.0j) ^ (0.0 + 0.0j)); // both-error {{invalid operands to binary expression}}
}

/// From test/SemaCXX/constant-expression-cxx11.cpp
///
/// Some of the diagnostics we emit are different than the one of the
/// current interpreter.
///
/// FIXME: For the '&test3 + 1' test, we are _not_ creating an explicit pointer variable
/// anywhere and so the &test3+1 is the same as __imag(test3) for us.
namespace ComplexConstexpr {
constexpr _Complex float test1 = {};
constexpr _Complex float test2 = {1};
constexpr _Complex double test3 = {1,2};
constexpr _Complex int test4 = {4};
constexpr _Complex int test5 = 4;
constexpr _Complex int test6 = {5,6};
typedef _Complex float fcomplex;
constexpr fcomplex test7 = fcomplex();

constexpr const double &t2r = __real test3;
constexpr const double &t2i = __imag test3;
static_assert(&t2r + 1 == &t2i, "");
static_assert(t2r == 1.0, "");
static_assert(t2i == 2.0, "");
constexpr const double *t2p = &t2r;
static_assert(t2p[-1] == 0.0, ""); // both-error {{constant expr}} \
// both-note {{cannot refer to element -1 of array of 2 elements}}
static_assert(t2p[0] == 1.0, "");
static_assert(t2p[1] == 2.0, "");
static_assert(t2p[2] == 0.0, ""); // both-error {{constant expr}} \
// both-note {{one-past-the-end pointer}}
static_assert(t2p[3] == 0.0, ""); // both-error {{constant expr}} \
// both-note {{cannot refer to element 3 of array of 2 elements}}
constexpr _Complex float *p = 0;
constexpr float pr = __real *p; // both-error {{constant expr}} \
// ref-note {{cannot access real component of null}} \
// expected-note {{read of dereferenced null pointer}}
constexpr float pi = __imag *p; // both-error {{constant expr}} \
// ref-note {{cannot access imaginary component of null}} \
// expected-note {{cannot perform pointer arithmetic on null pointer}}
constexpr const _Complex double *q = &test3 + 1;
constexpr double qr = __real *q; // ref-error {{constant expr}} \
// ref-note {{cannot access real component of pointer past the end}}
constexpr double qi = __imag *q; // both-error {{constant expr}} \
// ref-note {{cannot access imaginary component of pointer past the end}} \
// expected-note {{read of dereferenced one-past-the-end pointer}}

static_assert(__real test6 == 5, "");
static_assert(__imag test6 == 6, "");
static_assert(&__imag test6 == &__real test6 + 1, "");
}

0 comments on commit 2421e76

Please sign in to comment.