Files
gcc/gcc/testsuite/gcc.dg/c23-imaginary-constants-3.c
Jakub Jelinek eb45d151fa c: Implement C2Y N3298 - Introduce complex literals [PR117029]
The following patch implements the C2Y N3298 paper Introduce complex literals
by providing different (or no) diagnostics on imaginary constants (except
for integer ones).
For _DecimalN constants we don't support _Complex _DecimalN and error on any
i/j suffixes mixed with DD/DL/DF, so nothing changed there.

2024-11-13  Jakub Jelinek  <jakub@redhat.com>

	PR c/117029
libcpp/
	* include/cpplib.h (struct cpp_options): Add imaginary_constants
	member.
	* init.cc (struct lang_flags): Add imaginary_constants bitfield.
	(lang_defaults): Add column for imaginary_constants.
	(cpp_set_lang): Copy over imaginary_constants.
	* expr.cc (cpp_classify_number): Diagnose CPP_N_IMAGINARY
	non-CPP_N_FLOATING constants differently for C.
gcc/testsuite/
	* gcc.dg/cpp/pr7263-3.c: Adjust expected diagnostic wording.
	* gcc.dg/c23-imaginary-constants-1.c: New test.
	* gcc.dg/c23-imaginary-constants-2.c: New test.
	* gcc.dg/c23-imaginary-constants-3.c: New test.
	* gcc.dg/c23-imaginary-constants-4.c: New test.
	* gcc.dg/c23-imaginary-constants-5.c: New test.
	* gcc.dg/c23-imaginary-constants-6.c: New test.
	* gcc.dg/c23-imaginary-constants-7.c: New test.
	* gcc.dg/c23-imaginary-constants-8.c: New test.
	* gcc.dg/c23-imaginary-constants-9.c: New test.
	* gcc.dg/c23-imaginary-constants-10.c: New test.
	* gcc.dg/c2y-imaginary-constants-1.c: New test.
	* gcc.dg/c2y-imaginary-constants-2.c: New test.
	* gcc.dg/c2y-imaginary-constants-3.c: New test.
	* gcc.dg/c2y-imaginary-constants-4.c: New test.
	* gcc.dg/c2y-imaginary-constants-5.c: New test.
	* gcc.dg/c2y-imaginary-constants-6.c: New test.
	* gcc.dg/c2y-imaginary-constants-7.c: New test.
	* gcc.dg/c2y-imaginary-constants-8.c: New test.
	* gcc.dg/c2y-imaginary-constants-9.c: New test.
	* gcc.dg/c2y-imaginary-constants-10.c: New test.
	* gcc.dg/c2y-imaginary-constants-11.c: New test.
	* gcc.dg/c2y-imaginary-constants-12.c: New test.
2024-11-13 09:41:41 +01:00

65 lines
2.8 KiB
C

/* Test that imaginary constants are diagnosed in C23 mode: -pedantic. */
/* { dg-do run } */
/* { dg-options "-std=c23 -pedantic" } */
/* { dg-add-options float32 } */
/* { dg-add-options float64 } */
/* { dg-add-options float32x } */
/* { dg-require-effective-target float32 } */
/* { dg-require-effective-target float32x } */
/* { dg-require-effective-target float64 } */
_Complex _Float32 a = 1.if32; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32 b = 2.F32j; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32 c = 3.f32i; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32 d = 4.JF32; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64 e = 1.if64; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64 f = 2.F64j; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64 g = 3.f64i; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64 h = 4.JF64; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32x i = 1.if32x; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32x j = 2.F32xj; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32x k = 3.f32xI; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32x l = 4.JF32x; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
__extension__ _Complex _Float32 m = 1.if32;
__extension__ _Complex _Float32 n = 2.F32j;
__extension__ _Complex _Float32 o = 3.f32i;
__extension__ _Complex _Float32 p = 4.JF32;
__extension__ _Complex _Float64 q = 1.if64;
__extension__ _Complex _Float64 r = 2.F64j;
__extension__ _Complex _Float64 s = 3.f64i;
__extension__ _Complex _Float64 t = 4.JF64;
__extension__ _Complex _Float32x u = 1.if32x;
__extension__ _Complex _Float32x v = 2.F32xj;
__extension__ _Complex _Float32x w = 3.f32xI;
__extension__ _Complex _Float32x x = 4.JF32x;
int
main ()
{
if (a * a != -1.f32
|| b * b != -4.f32
|| c * c != -9.f32
|| d * d != -16.f32
|| e * e != -1.f64
|| f * f != -4.f64
|| g * g != -9.f64
|| h * h != -16.f64
|| i * i != -1.f32x
|| j * j != -4.f32x
|| k * k != -9.f32x
|| l * l != -16.f32x
|| m * m != -1.f32
|| n * n != -4.f32
|| o * o != -9.f32
|| p * p != -16.f32
|| q * q != -1.f64
|| r * r != -4.f64
|| s * s != -9.f64
|| t * t != -16.f64
|| u * u != -1.f32x
|| v * v != -4.f32x
|| w * w != -9.f32x
|| x * x != -16.f32x)
__builtin_abort ();
}