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.
This commit is contained in:
Jakub Jelinek 2024-11-13 09:41:41 +01:00 committed by Jakub Jelinek
parent 9b2915d95d
commit eb45d151fa
26 changed files with 594 additions and 35 deletions

View File

@ -0,0 +1,58 @@
/* Test that imaginary constants are diagnosed in C23 mode: -pedantic. */
/* { dg-do run } */
/* { dg-options "-std=c23 -pedantic" } */
_Complex float a = 1.if; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex float b = 2.Fj; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex float c = 3.fI; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex float d = 4.JF; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex double e = 1.i; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex double f = 2.j; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex double g = 3.I; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex double h = 4.J; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex long double i = 1.il; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex long double j = 2.Lj; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex long double k = 3.lI; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex long double l = 4.JL; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
__extension__ _Complex float m = 1.if;
__extension__ _Complex float n = 2.Fj;
__extension__ _Complex float o = 3.fI;
__extension__ _Complex float p = 4.JF;
__extension__ _Complex double q = 1.i;
__extension__ _Complex double r = 2.j;
__extension__ _Complex double s = 3.I;
__extension__ _Complex double t = 4.J;
__extension__ _Complex long double u = 1.il;
__extension__ _Complex long double v = 2.Lj;
__extension__ _Complex long double w = 3.lI;
__extension__ _Complex long double x = 4.JL;
int
main ()
{
if (a * a != -1.f
|| b * b != -4.f
|| c * c != -9.f
|| d * d != -16.f
|| e * e != -1.
|| f * f != -4.
|| g * g != -9.
|| h * h != -16.
|| i * i != -1.L
|| j * j != -4.L
|| k * k != -9.L
|| l * l != -16.L
|| m * m != -1.f
|| n * n != -4.f
|| o * o != -9.f
|| p * p != -16.f
|| q * q != -1.
|| r * r != -4.
|| s * s != -9.
|| t * t != -16.
|| u * u != -1.L
|| v * v != -4.L
|| w * w != -9.L
|| x * x != -16.L)
__builtin_abort ();
}

View File

@ -0,0 +1,14 @@
/* Test that imaginary constants are diagnosed in C23 mode: -pedantic-errors. */
/* { dg-do compile } */
/* { dg-options "-std=c23 -pedantic-errors" } */
/* { dg-add-options float64x } */
/* { dg-require-effective-target float64x } */
_Complex _Float64x a = 1.if64x; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64x b = 2.F64xj; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64x c = 3.f64xi; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64x d = 4.JF64x; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
__extension__ _Complex _Float64x e = 1.if64x;
__extension__ _Complex _Float64x f = 2.F64xj;
__extension__ _Complex _Float64x g = 3.f64xi;
__extension__ _Complex _Float64x h = 4.JF64x;

View File

@ -0,0 +1,28 @@
/* Test that imaginary constants are diagnosed in C23 mode: -pedantic-errors. */
/* { dg-do compile } */
/* { dg-options "-std=c23 -pedantic-errors" } */
_Complex float a = 1.if; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex float b = 2.Fj; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex float c = 3.fI; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex float d = 4.JF; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex double e = 1.i; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex double f = 2.j; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex double g = 3.I; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex double h = 4.J; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex long double i = 1.il; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex long double j = 2.Lj; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex long double k = 3.lI; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex long double l = 4.JL; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
__extension__ _Complex float m = 1.if;
__extension__ _Complex float n = 2.Fj;
__extension__ _Complex float o = 3.fI;
__extension__ _Complex float p = 4.JF;
__extension__ _Complex double q = 1.i;
__extension__ _Complex double r = 2.j;
__extension__ _Complex double s = 3.I;
__extension__ _Complex double t = 4.J;
__extension__ _Complex long double u = 1.il;
__extension__ _Complex long double v = 2.Lj;
__extension__ _Complex long double w = 3.lI;
__extension__ _Complex long double x = 4.JL;

View File

@ -0,0 +1,64 @@
/* 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 ();
}

View File

@ -0,0 +1,34 @@
/* Test that imaginary constants are diagnosed in C23 mode: -pedantic-errors. */
/* { dg-do compile } */
/* { dg-options "-std=c23 -pedantic-errors" } */
/* { 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-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32 b = 2.F32j; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32 c = 3.f32i; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32 d = 4.JF32; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64 e = 1.if64; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64 f = 2.F64j; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64 g = 3.f64i; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64 h = 4.JF64; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32x i = 1.if32x; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32x j = 2.F32xj; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32x k = 3.f32xI; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float32x l = 4.JF32x; /* { dg-error "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;

View File

@ -0,0 +1,28 @@
/* Test that imaginary constants are diagnosed in C23 mode: -pedantic. */
/* { dg-do run } */
/* { dg-options "-std=c23 -pedantic" } */
/* { dg-add-options float128 } */
/* { dg-require-effective-target float128 } */
_Complex _Float128 a = 1.if128; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float128 b = 2.F128j; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float128 c = 3.f128i; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float128 d = 4.JF128; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
__extension__ _Complex _Float128 e = 1.if128;
__extension__ _Complex _Float128 f = 2.F128j;
__extension__ _Complex _Float128 g = 3.f128i;
__extension__ _Complex _Float128 h = 4.JF128;
int
main ()
{
if (a * a != -1.f128
|| b * b != -4.f128
|| c * c != -9.f128
|| d * d != -16.f128
|| e * e != -1.f128
|| f * f != -4.f128
|| g * g != -9.f128
|| h * h != -16.f128)
__builtin_abort ();
}

View File

@ -0,0 +1,14 @@
/* Test that imaginary constants are diagnosed in C23 mode: -pedantic-errors. */
/* { dg-do compile } */
/* { dg-options "-std=c23 -pedantic-errors" } */
/* { dg-add-options float128 } */
/* { dg-require-effective-target float128 } */
_Complex _Float128 a = 1.if128; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float128 b = 2.F128j; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float128 c = 3.f128i; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float128 d = 4.JF128; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
__extension__ _Complex _Float128 e = 1.if128;
__extension__ _Complex _Float128 f = 2.F128j;
__extension__ _Complex _Float128 g = 3.f128i;
__extension__ _Complex _Float128 h = 4.JF128;

View File

@ -0,0 +1,28 @@
/* Test that imaginary constants are diagnosed in C23 mode: -pedantic. */
/* { dg-do run } */
/* { dg-options "-std=c23 -pedantic" } */
/* { dg-add-options float16 } */
/* { dg-require-effective-target float16 } */
_Complex _Float16 a = 1.if16; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float16 b = 2.F16j; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float16 c = 3.f16i; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float16 d = 4.JF16; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
__extension__ _Complex _Float16 e = 1.if16;
__extension__ _Complex _Float16 f = 2.F16j;
__extension__ _Complex _Float16 g = 3.f16i;
__extension__ _Complex _Float16 h = 4.JF16;
int
main ()
{
if (a * a != -1.f16
|| b * b != -4.f16
|| c * c != -9.f16
|| d * d != -16.f16
|| e * e != -1.f16
|| f * f != -4.f16
|| g * g != -9.f16
|| h * h != -16.f16)
__builtin_abort ();
}

View File

@ -0,0 +1,14 @@
/* Test that imaginary constants are diagnosed in C23 mode: -pedantic-errors. */
/* { dg-do compile } */
/* { dg-options "-std=c23 -pedantic-errors" } */
/* { dg-add-options float16 } */
/* { dg-require-effective-target float16 } */
_Complex _Float16 a = 1.if16; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float16 b = 2.F16j; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float16 c = 3.f16i; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float16 d = 4.JF16; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
__extension__ _Complex _Float16 e = 1.if16;
__extension__ _Complex _Float16 f = 2.F16j;
__extension__ _Complex _Float16 g = 3.f16i;
__extension__ _Complex _Float16 h = 4.JF16;

View File

@ -0,0 +1,28 @@
/* Test that imaginary constants are diagnosed in C23 mode: -pedantic. */
/* { dg-do run } */
/* { dg-options "-std=c23 -pedantic" } */
/* { dg-add-options float64x } */
/* { dg-require-effective-target float64x } */
_Complex _Float64x a = 1.if64x; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64x b = 2.F64xj; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64x c = 3.f64xi; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
_Complex _Float64x d = 4.JF64x; /* { dg-warning "imaginary constants are a C2Y feature or GCC extension" } */
__extension__ _Complex _Float64x e = 1.if64x;
__extension__ _Complex _Float64x f = 2.F64xj;
__extension__ _Complex _Float64x g = 3.f64xi;
__extension__ _Complex _Float64x h = 4.JF64x;
int
main ()
{
if (a * a != -1.f64x
|| b * b != -4.f64x
|| c * c != -9.f64x
|| d * d != -16.f64x
|| e * e != -1.f64x
|| f * f != -4.f64x
|| g * g != -9.f64x
|| h * h != -16.f64x)
__builtin_abort ();
}

View File

@ -0,0 +1,5 @@
/* Test that imaginary constants are accepted in C2Y mode: -pedantic. */
/* { dg-do run } */
/* { dg-options "-std=c2y -pedantic" } */
#include "c23-imaginary-constants-1.c"

View File

@ -0,0 +1,14 @@
/* Test that imaginary constants are accepted in C2Y mode: compat warnings. */
/* { dg-do compile } */
/* { dg-options "-std=c2y -Wc23-c2y-compat" } */
/* { dg-add-options float64x } */
/* { dg-require-effective-target float64x } */
_Complex _Float64x a = 1.if64x; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float64x b = 2.F64xj; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float64x c = 3.f64xi; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float64x d = 4.JF64x; /* { dg-warning "imaginary constants are a C2Y feature" } */
__extension__ _Complex _Float64x e = 1.if64x;
__extension__ _Complex _Float64x f = 2.F64xj;
__extension__ _Complex _Float64x g = 3.f64xi;
__extension__ _Complex _Float64x h = 4.JF64x;

View File

@ -0,0 +1,58 @@
/* Test that integral imaginary constants are diagnosed in C2Y mode: -pedantic. */
/* { dg-do run } */
/* { dg-options "-std=gnu2y -pedantic" } */
_Complex float a = 1i; /* { dg-warning "imaginary constants are a GCC extension" } */
_Complex float b = 2j; /* { dg-warning "imaginary constants are a GCC extension" } */
_Complex float c = 3I; /* { dg-warning "imaginary constants are a GCC extension" } */
_Complex float d = 4J; /* { dg-warning "imaginary constants are a GCC extension" } */
_Complex double e = 1il; /* { dg-warning "imaginary constants are a GCC extension" } */
_Complex double f = 2Lj; /* { dg-warning "imaginary constants are a GCC extension" } */
_Complex double g = 3lI; /* { dg-warning "imaginary constants are a GCC extension" } */
_Complex double h = 4JL; /* { dg-warning "imaginary constants are a GCC extension" } */
_Complex long double i = 1ill; /* { dg-warning "imaginary constants are a GCC extension" } */
_Complex long double j = 2LLj; /* { dg-warning "imaginary constants are a GCC extension" } */
_Complex long double k = 3llI; /* { dg-warning "imaginary constants are a GCC extension" } */
_Complex long double l = 4JLL; /* { dg-warning "imaginary constants are a GCC extension" } */
__extension__ _Complex float m = 1i;
__extension__ _Complex float n = 2j;
__extension__ _Complex float o = 3I;
__extension__ _Complex float p = 4J;
__extension__ _Complex double q = 1il;
__extension__ _Complex double r = 2Lj;
__extension__ _Complex double s = 3lI;
__extension__ _Complex double t = 4JL;
__extension__ _Complex long double u = 1ill;
__extension__ _Complex long double v = 2LLj;
__extension__ _Complex long double w = 3llI;
__extension__ _Complex long double x = 4JLL;
int
main ()
{
if (a * a != -1.f
|| b * b != -4.f
|| c * c != -9.f
|| d * d != -16.f
|| e * e != -1.
|| f * f != -4.
|| g * g != -9.
|| h * h != -16.
|| i * i != -1.L
|| j * j != -4.L
|| k * k != -9.L
|| l * l != -16.L
|| m * m != -1.f
|| n * n != -4.f
|| o * o != -9.f
|| p * p != -16.f
|| q * q != -1.
|| r * r != -4.
|| s * s != -9.
|| t * t != -16.
|| u * u != -1.L
|| v * v != -4.L
|| w * w != -9.L
|| x * x != -16.L)
__builtin_abort ();
}

View File

@ -0,0 +1,28 @@
/* Test that integral imaginary constants are diagnosed in C2Y mode: -pedantic-errors. */
/* { dg-do compile } */
/* { dg-options "-std=gnu2y -pedantic-errors" } */
_Complex float a = 1i; /* { dg-error "imaginary constants are a GCC extension" } */
_Complex float b = 2j; /* { dg-error "imaginary constants are a GCC extension" } */
_Complex float c = 3I; /* { dg-error "imaginary constants are a GCC extension" } */
_Complex float d = 4J; /* { dg-error "imaginary constants are a GCC extension" } */
_Complex double e = 1il; /* { dg-error "imaginary constants are a GCC extension" } */
_Complex double f = 2Lj; /* { dg-error "imaginary constants are a GCC extension" } */
_Complex double g = 3lI; /* { dg-error "imaginary constants are a GCC extension" } */
_Complex double h = 4JL; /* { dg-error "imaginary constants are a GCC extension" } */
_Complex long double i = 1ill; /* { dg-error "imaginary constants are a GCC extension" } */
_Complex long double j = 2LLj; /* { dg-error "imaginary constants are a GCC extension" } */
_Complex long double k = 3llI; /* { dg-error "imaginary constants are a GCC extension" } */
_Complex long double l = 4JLL; /* { dg-error "imaginary constants are a GCC extension" } */
__extension__ _Complex float m = 1i;
__extension__ _Complex float n = 2j;
__extension__ _Complex float o = 3I;
__extension__ _Complex float p = 4J;
__extension__ _Complex double q = 1il;
__extension__ _Complex double r = 2Lj;
__extension__ _Complex double s = 3lI;
__extension__ _Complex double t = 4JL;
__extension__ _Complex long double u = 1ill;
__extension__ _Complex long double v = 2LLj;
__extension__ _Complex long double w = 3llI;
__extension__ _Complex long double x = 4JLL;

View File

@ -0,0 +1,28 @@
/* Test that imaginary constants are accepted in C2Y mode: compat warnings. */
/* { dg-do compile } */
/* { dg-options "-std=c2y -Wc23-c2y-compat" } */
_Complex float a = 1.if; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex float b = 2.Fj; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex float c = 3.fI; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex float d = 4.JF; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex double e = 1.i; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex double f = 2.j; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex double g = 3.I; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex double h = 4.J; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex long double i = 1.il; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex long double j = 2.Lj; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex long double k = 3.lI; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex long double l = 4.JL; /* { dg-warning "imaginary constants are a C2Y feature" } */
__extension__ _Complex float m = 1.if;
__extension__ _Complex float n = 2.Fj;
__extension__ _Complex float o = 3.fI;
__extension__ _Complex float p = 4.JF;
__extension__ _Complex double q = 1.i;
__extension__ _Complex double r = 2.j;
__extension__ _Complex double s = 3.I;
__extension__ _Complex double t = 4.J;
__extension__ _Complex long double u = 1.il;
__extension__ _Complex long double v = 2.Lj;
__extension__ _Complex long double w = 3.lI;
__extension__ _Complex long double x = 4.JL;

View File

@ -0,0 +1,11 @@
/* Test that imaginary constants are accepted in C2Y mode: -pedantic. */
/* { dg-do run } */
/* { dg-options "-std=c2y -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 } */
#include "c23-imaginary-constants-3.c"

View File

@ -0,0 +1,34 @@
/* Test that imaginary constants are accepted in C2Y mode: compat warnings. */
/* { dg-do compile } */
/* { dg-options "-std=c2y -Wc23-c2y-compat" } */
/* { 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" } */
_Complex _Float32 b = 2.F32j; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float32 c = 3.f32i; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float32 d = 4.JF32; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float64 e = 1.if64; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float64 f = 2.F64j; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float64 g = 3.f64i; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float64 h = 4.JF64; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float32x i = 1.if32x; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float32x j = 2.F32xj; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float32x k = 3.f32xI; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float32x l = 4.JF32x; /* { dg-warning "imaginary constants are a C2Y feature" } */
__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;

View File

@ -0,0 +1,7 @@
/* Test that imaginary constants are accepted in C2Y mode: -pedantic. */
/* { dg-do run } */
/* { dg-options "-std=c2y -pedantic" } */
/* { dg-add-options float128 } */
/* { dg-require-effective-target float128 } */
#include "c23-imaginary-constants-5.c"

View File

@ -0,0 +1,14 @@
/* Test that imaginary constants are accepted in C2Y mode: compat warnings. */
/* { dg-do compile } */
/* { dg-options "-std=c2y -Wc23-c2y-compat" } */
/* { dg-add-options float128 } */
/* { dg-require-effective-target float128 } */
_Complex _Float128 a = 1.if128; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float128 b = 2.F128j; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float128 c = 3.f128i; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float128 d = 4.JF128; /* { dg-warning "imaginary constants are a C2Y feature" } */
__extension__ _Complex _Float128 e = 1.if128;
__extension__ _Complex _Float128 f = 2.F128j;
__extension__ _Complex _Float128 g = 3.f128i;
__extension__ _Complex _Float128 h = 4.JF128;

View File

@ -0,0 +1,7 @@
/* Test that imaginary constants are accepted in C2Y mode: -pedantic. */
/* { dg-do run } */
/* { dg-options "-std=c2y -pedantic" } */
/* { dg-add-options float16 } */
/* { dg-require-effective-target float16 } */
#include "c23-imaginary-constants-7.c"

View File

@ -0,0 +1,14 @@
/* Test that imaginary constants are accepted in C2Y mode: compat warnings. */
/* { dg-do compile } */
/* { dg-options "-std=c2y -Wc23-c2y-compat" } */
/* { dg-add-options float16 } */
/* { dg-require-effective-target float16 } */
_Complex _Float16 a = 1.if16; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float16 b = 2.F16j; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float16 c = 3.f16i; /* { dg-warning "imaginary constants are a C2Y feature" } */
_Complex _Float16 d = 4.JF16; /* { dg-warning "imaginary constants are a C2Y feature" } */
__extension__ _Complex _Float16 e = 1.if16;
__extension__ _Complex _Float16 f = 2.F16j;
__extension__ _Complex _Float16 g = 3.f16i;
__extension__ _Complex _Float16 h = 4.JF16;

View File

@ -0,0 +1,7 @@
/* Test that imaginary constants are accepted in C2Y mode: -pedantic. */
/* { dg-do run } */
/* { dg-options "-std=c2y -pedantic" } */
/* { dg-add-options float64x } */
/* { dg-require-effective-target float64x } */
#include "c23-imaginary-constants-9.c"

View File

@ -15,5 +15,5 @@ bar2 ()
__complex__ bar3 () /* { dg-error "ISO C does not support plain .complex. meaning .double complex." } */
{
return _Complex_I; /* { dg-error "imaginary constants are a GCC extension" } */
return _Complex_I; /* { dg-error "imaginary constants are a C2Y feature or GCC extension" } */
}

View File

@ -911,8 +911,25 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
syntax_ok:
if (result & CPP_N_IMAGINARY)
cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, virtual_location, 0,
"imaginary constants are a GCC extension");
{
if (CPP_OPTION (pfile, cplusplus) || (result & CPP_N_FLOATING) == 0)
cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, virtual_location, 0,
"imaginary constants are a GCC extension");
else
{
bool warned = false;
if (!CPP_OPTION (pfile, imaginary_constants) && CPP_PEDANTIC (pfile))
warned
= cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC,
virtual_location, 0,
"imaginary constants are a C2Y "
"feature or GCC extension");
if (!warned && CPP_OPTION (pfile, cpp_warn_c23_c2y_compat) > 0)
cpp_warning_with_line (pfile, CPP_W_C23_C2Y_COMPAT,
virtual_location, 0,
"imaginary constants are a C2Y feature");
}
}
if (radix == 2)
{
bool warned = false;

View File

@ -524,6 +524,9 @@ struct cpp_options
/* Nonzero for C++ 2014 Standard binary constants. */
unsigned char binary_constants;
/* Nonzero for C2Y imaginary (floating) constants. */
unsigned char imaginary_constants;
/* Nonzero for C++ 2014 Standard digit separators. */
unsigned char digit_separators;

View File

@ -112,44 +112,45 @@ struct lang_flags
unsigned int octal_constants : 1;
unsigned int true_false : 1;
unsigned int embed : 1;
unsigned int imaginary_constants : 1;
};
static const struct lang_flags lang_defaults[] = {
/* u e w n
b d 8 l a a t
x u i i c v s s i r d m o r e
x i d u r d n g t h a c z f n e e c u m
c c n x c d s i l l l c s r l o o d l d d l d t f b
9 + u i 1 i t g i i i s e i i p p f i e i i u a a e
9 + m d 1 d d r t t t t p g t t e p t f r m c l l d */
/* GNUC89 */ { 0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0 },
/* GNUC99 */ { 1,0,1,1,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0 },
/* GNUC11 */ { 1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0 },
/* GNUC17 */ { 1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0 },
/* GNUC23 */ { 1,0,1,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,0,0,1,1 },
/* GNUC2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1,0,0,0,0,0,0,0,1,0 },
/* GNUCXX20 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,1,0 },
/* CXX20 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,1,0 },
/* GNUCXX23 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0 },
/* CXX23 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0 },
/* GNUCXX26 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0 },
/* CXX26 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0 },
/* ASM */ { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
x i d u r d n g t h a c z f n e e c u m i
c c n x c d s i l l l c s r l o o d l d d l d t f b m
9 + u i 1 i t g i i i s e i i p p f i e i i u a a e a
9 + m d 1 d d r t t t t p g t t e p t f r m c l l d g */
/* GNUC89 */ { 0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0 },
/* GNUC99 */ { 1,0,1,1,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0 },
/* GNUC11 */ { 1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0 },
/* GNUC17 */ { 1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0 },
/* GNUC23 */ { 1,0,1,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,0,0,1,1,0 },
/* GNUC2Y */ { 1,0,1,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,1,0,1,1,1,1 },
/* STDC89 */ { 0,0,0,0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0,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,1,0,0 },
/* CXX20 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,1,0,0 },
/* GNUCXX23 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0,0 },
/* CXX23 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0,0 },
/* GNUCXX26 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0,0 },
/* CXX26 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0,0 },
/* ASM */ { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
};
/* Sets internal flags correctly for a given language. */
@ -186,6 +187,7 @@ cpp_set_lang (cpp_reader *pfile, enum c_lang lang)
CPP_OPTION (pfile, octal_constants) = l->octal_constants;
CPP_OPTION (pfile, true_false) = l->true_false;
CPP_OPTION (pfile, embed) = l->embed;
CPP_OPTION (pfile, imaginary_constants) = l->imaginary_constants;
}
/* Initialize library global state. */