Skip to content

Commit 7bb01e4

Browse files
jakubjelinekLiaoshihua
authored andcommitted
c: Don't pedwarn on _FloatN{,x} or {f,F}N{,x} suffixes for C2X
Now that _Float{16,32,64,128,32x,64x,128x} and {f,F}{16,32,64,128,32x,64x,128x} literal suffixes are in C23 standard, I think it is undesirable to pedwarn about these for -std=c2x, so this patch uses pedwarn_c11 instead. In c-family/, we don't have that function and am not sure it would be very clean to define dummy pedwarn_c11 in the C++ FE, so the patch just does what pedwarn_c11 does using pedwarn/warning. 2023-09-06 Jakub Jelinek <[email protected]> gcc/c-family/ * c-lex.cc (interpret_float): For C diagnostics on FN and FNx suffixes append " before C2X" to diagnostics text and follow behavior of pedwarn_c11. gcc/c/ * c-decl.cc (declspecs_add_type): Use pedwarn_c11 rather than pedwarn for _FloatN{,x} diagnostics and append " before C2X" to the diagnostic text. gcc/testsuite/ * gcc.dg/c11-floatn-1.c: New test. * gcc.dg/c11-floatn-2.c: New test. * gcc.dg/c11-floatn-3.c: New test. * gcc.dg/c11-floatn-4.c: New test. * gcc.dg/c11-floatn-5.c: New test. * gcc.dg/c11-floatn-6.c: New test. * gcc.dg/c11-floatn-7.c: New test. * gcc.dg/c11-floatn-8.c: New test. * gcc.dg/c2x-floatn-1.c: New test. * gcc.dg/c2x-floatn-2.c: New test. * gcc.dg/c2x-floatn-3.c: New test. * gcc.dg/c2x-floatn-4.c: New test. * gcc.dg/c2x-floatn-5.c: New test. * gcc.dg/c2x-floatn-6.c: New test. * gcc.dg/c2x-floatn-7.c: New test. * gcc.dg/c2x-floatn-8.c: New test.
1 parent b13b0dd commit 7bb01e4

18 files changed

+218
-7
lines changed

gcc/c-family/c-lex.cc

+19-1
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,25 @@ interpret_float (const cpp_token *token, unsigned int flags,
10211021
error ("unsupported non-standard suffix on floating constant");
10221022
return error_mark_node;
10231023
}
1024-
else if (c_dialect_cxx () && !extended)
1024+
else if (!c_dialect_cxx ())
1025+
{
1026+
if (warn_c11_c2x_compat > 0)
1027+
{
1028+
if (pedantic && !flag_isoc2x)
1029+
pedwarn (input_location, OPT_Wc11_c2x_compat,
1030+
"non-standard suffix on floating constant "
1031+
"before C2X");
1032+
else
1033+
warning (OPT_Wc11_c2x_compat,
1034+
"non-standard suffix on floating constant "
1035+
"before C2X");
1036+
}
1037+
else if (warn_c11_c2x_compat != 0 && pedantic && !flag_isoc2x)
1038+
pedwarn (input_location, OPT_Wpedantic,
1039+
"non-standard suffix on floating constant "
1040+
"before C2X");
1041+
}
1042+
else if (!extended)
10251043
{
10261044
if (cxx_dialect < cxx23)
10271045
pedwarn (input_location, OPT_Wpedantic,

gcc/c/c-decl.cc

+7-6
Original file line numberDiff line numberDiff line change
@@ -12117,12 +12117,13 @@ declspecs_add_type (location_t loc, struct c_declspecs *specs,
1211712117
CASE_RID_FLOATN_NX:
1211812118
specs->floatn_nx_idx = i - RID_FLOATN_NX_FIRST;
1211912119
if (!in_system_header_at (input_location))
12120-
pedwarn (loc, OPT_Wpedantic,
12121-
"ISO C does not support the %<_Float%d%s%> type",
12122-
floatn_nx_types[specs->floatn_nx_idx].n,
12123-
(floatn_nx_types[specs->floatn_nx_idx].extended
12124-
? "x"
12125-
: ""));
12120+
pedwarn_c11 (loc, OPT_Wpedantic,
12121+
"ISO C does not support the %<_Float%d%s%> type"
12122+
" before C2X",
12123+
floatn_nx_types[specs->floatn_nx_idx].n,
12124+
(floatn_nx_types[specs->floatn_nx_idx].extended
12125+
? "x"
12126+
: ""));
1212612127

1212712128
if (specs->long_p)
1212812129
error_at (loc,

gcc/testsuite/gcc.dg/c11-floatn-1.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c11 -pedantic-errors" } */
3+
/* { dg-add-options float32 } */
4+
/* { dg-add-options float64 } */
5+
/* { dg-add-options float32x } */
6+
/* { dg-require-effective-target float32 } */
7+
/* { dg-require-effective-target float32x } */
8+
/* { dg-require-effective-target float64 } */
9+
10+
_Float32 a /* { dg-error "ISO C does not support the '_Float32' type before C2X" } */
11+
= 1.0F32; /* { dg-error "non-standard suffix on floating constant before C2X" } */
12+
_Float64 b /* { dg-error "ISO C does not support the '_Float64' type before C2X" } */
13+
= 1.0F64; /* { dg-error "non-standard suffix on floating constant before C2X" } */
14+
_Float32x c /* { dg-error "ISO C does not support the '_Float32x' type before C2X" } */
15+
= 1.0F32x; /* { dg-error "non-standard suffix on floating constant before C2X" } */
16+
__extension__ _Float32 d
17+
= 2.0F32;
18+
__extension__ _Float64 e
19+
= 2.0F64;
20+
__extension__ _Float32x f
21+
= 2.0F32x;

gcc/testsuite/gcc.dg/c11-floatn-2.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c11 -pedantic-errors" } */
3+
/* { dg-add-options float128 } */
4+
/* { dg-require-effective-target float128 } */
5+
6+
_Float128 a /* { dg-error "ISO C does not support the '_Float128' type before C2X" } */
7+
= 1.0F128; /* { dg-error "non-standard suffix on floating constant before C2X" } */
8+
__extension__ _Float128 b
9+
= 2.0F128;

gcc/testsuite/gcc.dg/c11-floatn-3.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c11 -pedantic-errors" } */
3+
/* { dg-add-options float16 } */
4+
/* { dg-require-effective-target float16 } */
5+
6+
_Float16 a /* { dg-error "ISO C does not support the '_Float16' type before C2X" } */
7+
= 1.0F16; /* { dg-error "non-standard suffix on floating constant before C2X" } */
8+
__extension__ _Float16 b
9+
= 2.0F16;

gcc/testsuite/gcc.dg/c11-floatn-4.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c11 -pedantic-errors" } */
3+
/* { dg-add-options float64x } */
4+
/* { dg-require-effective-target float64x } */
5+
6+
_Float64x a /* { dg-error "ISO C does not support the '_Float64x' type before C2X" } */
7+
= 1.0F64x; /* { dg-error "non-standard suffix on floating constant before C2X" } */
8+
__extension__ _Float64x b
9+
= 2.0F64x;

gcc/testsuite/gcc.dg/c11-floatn-5.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c11 -Wc11-c2x-compat" } */
3+
/* { dg-add-options float32 } */
4+
/* { dg-add-options float64 } */
5+
/* { dg-add-options float32x } */
6+
/* { dg-require-effective-target float32 } */
7+
/* { dg-require-effective-target float32x } */
8+
/* { dg-require-effective-target float64 } */
9+
10+
_Float32 a /* { dg-warning "ISO C does not support the '_Float32' type before C2X" } */
11+
= 1.0F32; /* { dg-warning "non-standard suffix on floating constant before C2X" } */
12+
_Float64 b /* { dg-warning "ISO C does not support the '_Float64' type before C2X" } */
13+
= 1.0F64; /* { dg-warning "non-standard suffix on floating constant before C2X" } */
14+
_Float32x c /* { dg-warning "ISO C does not support the '_Float32x' type before C2X" } */
15+
= 1.0F32x; /* { dg-warning "non-standard suffix on floating constant before C2X" } */
16+
__extension__ _Float32 d
17+
= 2.0F32;
18+
__extension__ _Float64 e
19+
= 2.0F64;
20+
__extension__ _Float32x f
21+
= 2.0F32x;

gcc/testsuite/gcc.dg/c11-floatn-6.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c11 -Wc11-c2x-compat" } */
3+
/* { dg-add-options float128 } */
4+
/* { dg-require-effective-target float128 } */
5+
6+
_Float128 a /* { dg-warning "ISO C does not support the '_Float128' type before C2X" } */
7+
= 1.0F128; /* { dg-warning "non-standard suffix on floating constant before C2X" } */
8+
__extension__ _Float128 b
9+
= 2.0F128;

gcc/testsuite/gcc.dg/c11-floatn-7.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c11 -Wc11-c2x-compat" } */
3+
/* { dg-add-options float16 } */
4+
/* { dg-require-effective-target float16 } */
5+
6+
_Float16 a /* { dg-warning "ISO C does not support the '_Float16' type before C2X" } */
7+
= 1.0F16; /* { dg-warning "non-standard suffix on floating constant before C2X" } */
8+
__extension__ _Float16 b
9+
= 2.0F16;

gcc/testsuite/gcc.dg/c11-floatn-8.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c11 -Wc11-c2x-compat" } */
3+
/* { dg-add-options float64x } */
4+
/* { dg-require-effective-target float64x } */
5+
6+
_Float64x a /* { dg-warning "ISO C does not support the '_Float64x' type before C2X" } */
7+
= 1.0F64x; /* { dg-warning "non-standard suffix on floating constant before C2X" } */
8+
__extension__ _Float64x b
9+
= 2.0F64x;

gcc/testsuite/gcc.dg/c2x-floatn-1.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c2x -pedantic-errors" } */
3+
/* { dg-add-options float32 } */
4+
/* { dg-add-options float64 } */
5+
/* { dg-add-options float32x } */
6+
/* { dg-require-effective-target float32 } */
7+
/* { dg-require-effective-target float32x } */
8+
/* { dg-require-effective-target float64 } */
9+
10+
_Float32 a
11+
= 1.0F32;
12+
_Float64 b
13+
= 1.0F64;
14+
_Float32x c
15+
= 1.0F32x;
16+
__extension__ _Float32 d
17+
= 2.0F32;
18+
__extension__ _Float64 e
19+
= 2.0F64;
20+
__extension__ _Float32x f
21+
= 2.0F32x;

gcc/testsuite/gcc.dg/c2x-floatn-2.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c2x -pedantic-errors" } */
3+
/* { dg-add-options float128 } */
4+
/* { dg-require-effective-target float128 } */
5+
6+
_Float128 a
7+
= 1.0F128;
8+
__extension__ _Float128 b
9+
= 2.0F128;

gcc/testsuite/gcc.dg/c2x-floatn-3.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c2x -pedantic-errors" } */
3+
/* { dg-add-options float16 } */
4+
/* { dg-require-effective-target float16 } */
5+
6+
_Float16 a
7+
= 1.0F16;
8+
__extension__ _Float16 b
9+
= 2.0F16;

gcc/testsuite/gcc.dg/c2x-floatn-4.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c2x -pedantic-errors" } */
3+
/* { dg-add-options float64x } */
4+
/* { dg-require-effective-target float64x } */
5+
6+
_Float64x a
7+
= 1.0F64x;
8+
__extension__ _Float64x b
9+
= 2.0F64x;

gcc/testsuite/gcc.dg/c2x-floatn-5.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c2x -Wc11-c2x-compat" } */
3+
/* { dg-add-options float32 } */
4+
/* { dg-add-options float64 } */
5+
/* { dg-add-options float32x } */
6+
/* { dg-require-effective-target float32 } */
7+
/* { dg-require-effective-target float32x } */
8+
/* { dg-require-effective-target float64 } */
9+
10+
_Float32 a /* { dg-warning "ISO C does not support the '_Float32' type before C2X" } */
11+
= 1.0F32; /* { dg-warning "non-standard suffix on floating constant before C2X" } */
12+
_Float64 b /* { dg-warning "ISO C does not support the '_Float64' type before C2X" } */
13+
= 1.0F64; /* { dg-warning "non-standard suffix on floating constant before C2X" } */
14+
_Float32x c /* { dg-warning "ISO C does not support the '_Float32x' type before C2X" } */
15+
= 1.0F32x; /* { dg-warning "non-standard suffix on floating constant before C2X" } */
16+
__extension__ _Float32 d
17+
= 2.0F32;
18+
__extension__ _Float64 e
19+
= 2.0F64;
20+
__extension__ _Float32x f
21+
= 2.0F32x;

gcc/testsuite/gcc.dg/c2x-floatn-6.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c2x -Wc11-c2x-compat" } */
3+
/* { dg-add-options float128 } */
4+
/* { dg-require-effective-target float128 } */
5+
6+
_Float128 a /* { dg-warning "ISO C does not support the '_Float128' type before C2X" } */
7+
= 1.0F128; /* { dg-warning "non-standard suffix on floating constant before C2X" } */
8+
__extension__ _Float128 b
9+
= 2.0F128;

gcc/testsuite/gcc.dg/c2x-floatn-7.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c2x -Wc11-c2x-compat" } */
3+
/* { dg-add-options float16 } */
4+
/* { dg-require-effective-target float16 } */
5+
6+
_Float16 a /* { dg-warning "ISO C does not support the '_Float16' type before C2X" } */
7+
= 1.0F16; /* { dg-warning "non-standard suffix on floating constant before C2X" } */
8+
__extension__ _Float16 b
9+
= 2.0F16;

gcc/testsuite/gcc.dg/c2x-floatn-8.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-std=c2x -Wc11-c2x-compat" } */
3+
/* { dg-add-options float64x } */
4+
/* { dg-require-effective-target float64x } */
5+
6+
_Float64x a /* { dg-warning "ISO C does not support the '_Float64x' type before C2X" } */
7+
= 1.0F64x; /* { dg-warning "non-standard suffix on floating constant before C2X" } */
8+
__extension__ _Float64x b
9+
= 2.0F64x;

0 commit comments

Comments
 (0)