Skip to content

Commit 2421e76

Browse files
committed
[clang][Interp][NFC] Add more _Complex tests
1 parent a551cce commit 2421e76

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

clang/test/AST/Interp/complex.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,53 @@ namespace Cmp {
313313
static_assert((0.0 + 0.0j) > (0.0 + 0.0j)); // both-error {{invalid operands to binary expression}}
314314
static_assert((0.0 + 0.0j) ^ (0.0 + 0.0j)); // both-error {{invalid operands to binary expression}}
315315
}
316+
317+
/// From test/SemaCXX/constant-expression-cxx11.cpp
318+
///
319+
/// Some of the diagnostics we emit are different than the one of the
320+
/// current interpreter.
321+
///
322+
/// FIXME: For the '&test3 + 1' test, we are _not_ creating an explicit pointer variable
323+
/// anywhere and so the &test3+1 is the same as __imag(test3) for us.
324+
namespace ComplexConstexpr {
325+
constexpr _Complex float test1 = {};
326+
constexpr _Complex float test2 = {1};
327+
constexpr _Complex double test3 = {1,2};
328+
constexpr _Complex int test4 = {4};
329+
constexpr _Complex int test5 = 4;
330+
constexpr _Complex int test6 = {5,6};
331+
typedef _Complex float fcomplex;
332+
constexpr fcomplex test7 = fcomplex();
333+
334+
constexpr const double &t2r = __real test3;
335+
constexpr const double &t2i = __imag test3;
336+
static_assert(&t2r + 1 == &t2i, "");
337+
static_assert(t2r == 1.0, "");
338+
static_assert(t2i == 2.0, "");
339+
constexpr const double *t2p = &t2r;
340+
static_assert(t2p[-1] == 0.0, ""); // both-error {{constant expr}} \
341+
// both-note {{cannot refer to element -1 of array of 2 elements}}
342+
static_assert(t2p[0] == 1.0, "");
343+
static_assert(t2p[1] == 2.0, "");
344+
static_assert(t2p[2] == 0.0, ""); // both-error {{constant expr}} \
345+
// both-note {{one-past-the-end pointer}}
346+
static_assert(t2p[3] == 0.0, ""); // both-error {{constant expr}} \
347+
// both-note {{cannot refer to element 3 of array of 2 elements}}
348+
constexpr _Complex float *p = 0;
349+
constexpr float pr = __real *p; // both-error {{constant expr}} \
350+
// ref-note {{cannot access real component of null}} \
351+
// expected-note {{read of dereferenced null pointer}}
352+
constexpr float pi = __imag *p; // both-error {{constant expr}} \
353+
// ref-note {{cannot access imaginary component of null}} \
354+
// expected-note {{cannot perform pointer arithmetic on null pointer}}
355+
constexpr const _Complex double *q = &test3 + 1;
356+
constexpr double qr = __real *q; // ref-error {{constant expr}} \
357+
// ref-note {{cannot access real component of pointer past the end}}
358+
constexpr double qi = __imag *q; // both-error {{constant expr}} \
359+
// ref-note {{cannot access imaginary component of pointer past the end}} \
360+
// expected-note {{read of dereferenced one-past-the-end pointer}}
361+
362+
static_assert(__real test6 == 5, "");
363+
static_assert(__imag test6 == 6, "");
364+
static_assert(&__imag test6 == &__real test6 + 1, "");
365+
}

0 commit comments

Comments
 (0)