public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-3731] c: Don't pedwarn on _FloatN{, x} or {f, F}N{, x} suffixes for C2X
@ 2023-09-06  6:51 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2023-09-06  6:51 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:80acabb6dd05090db67805cdd358fe974b45e2ed

commit r14-3731-g80acabb6dd05090db67805cdd358fe974b45e2ed
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Sep 6 08:51:00 2023 +0200

    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  <jakub@redhat.com>
    
    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.

Diff:
---
 gcc/c-family/c-lex.cc               | 20 +++++++++++++++++++-
 gcc/c/c-decl.cc                     | 13 +++++++------
 gcc/testsuite/gcc.dg/c11-floatn-1.c | 21 +++++++++++++++++++++
 gcc/testsuite/gcc.dg/c11-floatn-2.c |  9 +++++++++
 gcc/testsuite/gcc.dg/c11-floatn-3.c |  9 +++++++++
 gcc/testsuite/gcc.dg/c11-floatn-4.c |  9 +++++++++
 gcc/testsuite/gcc.dg/c11-floatn-5.c | 21 +++++++++++++++++++++
 gcc/testsuite/gcc.dg/c11-floatn-6.c |  9 +++++++++
 gcc/testsuite/gcc.dg/c11-floatn-7.c |  9 +++++++++
 gcc/testsuite/gcc.dg/c11-floatn-8.c |  9 +++++++++
 gcc/testsuite/gcc.dg/c2x-floatn-1.c | 21 +++++++++++++++++++++
 gcc/testsuite/gcc.dg/c2x-floatn-2.c |  9 +++++++++
 gcc/testsuite/gcc.dg/c2x-floatn-3.c |  9 +++++++++
 gcc/testsuite/gcc.dg/c2x-floatn-4.c |  9 +++++++++
 gcc/testsuite/gcc.dg/c2x-floatn-5.c | 21 +++++++++++++++++++++
 gcc/testsuite/gcc.dg/c2x-floatn-6.c |  9 +++++++++
 gcc/testsuite/gcc.dg/c2x-floatn-7.c |  9 +++++++++
 gcc/testsuite/gcc.dg/c2x-floatn-8.c |  9 +++++++++
 18 files changed, 218 insertions(+), 7 deletions(-)

diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc
index d8aa2907c518..f72898f3ac87 100644
--- a/gcc/c-family/c-lex.cc
+++ b/gcc/c-family/c-lex.cc
@@ -1021,7 +1021,25 @@ interpret_float (const cpp_token *token, unsigned int flags,
 	    error ("unsupported non-standard suffix on floating constant");
 	    return error_mark_node;
 	  }
-	else if (c_dialect_cxx () && !extended)
+	else if (!c_dialect_cxx ())
+	  {
+	    if (warn_c11_c2x_compat > 0)
+	      {
+		if (pedantic && !flag_isoc2x)
+		  pedwarn (input_location, OPT_Wc11_c2x_compat,
+			   "non-standard suffix on floating constant "
+			   "before C2X");
+		else
+		  warning (OPT_Wc11_c2x_compat,
+			   "non-standard suffix on floating constant "
+			   "before C2X");
+	      }
+	    else if (warn_c11_c2x_compat != 0 && pedantic && !flag_isoc2x)
+	      pedwarn (input_location, OPT_Wpedantic,
+		       "non-standard suffix on floating constant "
+		       "before C2X");
+	  }
+	else if (!extended)
 	  {
 	    if (cxx_dialect < cxx23)
 	      pedwarn (input_location, OPT_Wpedantic,
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 1f9eb44dbaa2..e611d7a1abc1 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -12117,12 +12117,13 @@ declspecs_add_type (location_t loc, struct c_declspecs *specs,
 	    CASE_RID_FLOATN_NX:
 	      specs->floatn_nx_idx = i - RID_FLOATN_NX_FIRST;
 	      if (!in_system_header_at (input_location))
-		pedwarn (loc, OPT_Wpedantic,
-			 "ISO C does not support the %<_Float%d%s%> type",
-			 floatn_nx_types[specs->floatn_nx_idx].n,
-			 (floatn_nx_types[specs->floatn_nx_idx].extended
-			  ? "x"
-			  : ""));
+		pedwarn_c11 (loc, OPT_Wpedantic,
+			     "ISO C does not support the %<_Float%d%s%> type"
+			     " before C2X",
+			     floatn_nx_types[specs->floatn_nx_idx].n,
+			     (floatn_nx_types[specs->floatn_nx_idx].extended
+			      ? "x"
+			      : ""));
 
 	      if (specs->long_p)
 		error_at (loc,
diff --git a/gcc/testsuite/gcc.dg/c11-floatn-1.c b/gcc/testsuite/gcc.dg/c11-floatn-1.c
new file mode 100644
index 000000000000..82cae878b4ff
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-floatn-1.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -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 } */
+
+_Float32 a		/* { dg-error "ISO C does not support the '_Float32' type before C2X" } */
+  = 1.0F32;		/* { dg-error "non-standard suffix on floating constant before C2X" } */
+_Float64 b		/* { dg-error "ISO C does not support the '_Float64' type before C2X" } */
+  = 1.0F64;		/* { dg-error "non-standard suffix on floating constant before C2X" } */
+_Float32x c		/* { dg-error "ISO C does not support the '_Float32x' type before C2X" } */
+  = 1.0F32x;		/* { dg-error "non-standard suffix on floating constant before C2X" } */
+__extension__ _Float32 d
+  = 2.0F32;
+__extension__ _Float64 e
+  = 2.0F64;
+__extension__ _Float32x f
+  = 2.0F32x;
diff --git a/gcc/testsuite/gcc.dg/c11-floatn-2.c b/gcc/testsuite/gcc.dg/c11-floatn-2.c
new file mode 100644
index 000000000000..fafdb8e26fe5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-floatn-2.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+/* { dg-add-options float128 } */
+/* { dg-require-effective-target float128 } */
+
+_Float128 a		/* { dg-error "ISO C does not support the '_Float128' type before C2X" } */
+  = 1.0F128;		/* { dg-error "non-standard suffix on floating constant before C2X" } */
+__extension__ _Float128 b
+  = 2.0F128;
diff --git a/gcc/testsuite/gcc.dg/c11-floatn-3.c b/gcc/testsuite/gcc.dg/c11-floatn-3.c
new file mode 100644
index 000000000000..2268a9d83d14
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-floatn-3.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+/* { dg-add-options float16 } */
+/* { dg-require-effective-target float16 } */
+
+_Float16 a		/* { dg-error "ISO C does not support the '_Float16' type before C2X" } */
+  = 1.0F16;		/* { dg-error "non-standard suffix on floating constant before C2X" } */
+__extension__ _Float16 b
+  = 2.0F16;
diff --git a/gcc/testsuite/gcc.dg/c11-floatn-4.c b/gcc/testsuite/gcc.dg/c11-floatn-4.c
new file mode 100644
index 000000000000..8936ee2e49b1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-floatn-4.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+/* { dg-add-options float64x } */
+/* { dg-require-effective-target float64x } */
+
+_Float64x a		/* { dg-error "ISO C does not support the '_Float64x' type before C2X" } */
+  = 1.0F64x;		/* { dg-error "non-standard suffix on floating constant before C2X" } */
+__extension__ _Float64x b
+  = 2.0F64x;
diff --git a/gcc/testsuite/gcc.dg/c11-floatn-5.c b/gcc/testsuite/gcc.dg/c11-floatn-5.c
new file mode 100644
index 000000000000..1b4511494b2e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-floatn-5.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -Wc11-c2x-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 } */
+
+_Float32 a		/* { dg-warning "ISO C does not support the '_Float32' type before C2X" } */
+  = 1.0F32;		/* { dg-warning "non-standard suffix on floating constant before C2X" } */
+_Float64 b		/* { dg-warning "ISO C does not support the '_Float64' type before C2X" } */
+  = 1.0F64;		/* { dg-warning "non-standard suffix on floating constant before C2X" } */
+_Float32x c		/* { dg-warning "ISO C does not support the '_Float32x' type before C2X" } */
+  = 1.0F32x;		/* { dg-warning "non-standard suffix on floating constant before C2X" } */
+__extension__ _Float32 d
+  = 2.0F32;
+__extension__ _Float64 e
+  = 2.0F64;
+__extension__ _Float32x f
+  = 2.0F32x;
diff --git a/gcc/testsuite/gcc.dg/c11-floatn-6.c b/gcc/testsuite/gcc.dg/c11-floatn-6.c
new file mode 100644
index 000000000000..ebdb5ddcdedd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-floatn-6.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -Wc11-c2x-compat" } */
+/* { dg-add-options float128 } */
+/* { dg-require-effective-target float128 } */
+
+_Float128 a		/* { dg-warning "ISO C does not support the '_Float128' type before C2X" } */
+  = 1.0F128;		/* { dg-warning "non-standard suffix on floating constant before C2X" } */
+__extension__ _Float128 b
+  = 2.0F128;
diff --git a/gcc/testsuite/gcc.dg/c11-floatn-7.c b/gcc/testsuite/gcc.dg/c11-floatn-7.c
new file mode 100644
index 000000000000..005571d54429
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-floatn-7.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -Wc11-c2x-compat" } */
+/* { dg-add-options float16 } */
+/* { dg-require-effective-target float16 } */
+
+_Float16 a		/* { dg-warning "ISO C does not support the '_Float16' type before C2X" } */
+  = 1.0F16;		/* { dg-warning "non-standard suffix on floating constant before C2X" } */
+__extension__ _Float16 b
+  = 2.0F16;
diff --git a/gcc/testsuite/gcc.dg/c11-floatn-8.c b/gcc/testsuite/gcc.dg/c11-floatn-8.c
new file mode 100644
index 000000000000..f6d7228684eb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-floatn-8.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -Wc11-c2x-compat" } */
+/* { dg-add-options float64x } */
+/* { dg-require-effective-target float64x } */
+
+_Float64x a		/* { dg-warning "ISO C does not support the '_Float64x' type before C2X" } */
+  = 1.0F64x;		/* { dg-warning "non-standard suffix on floating constant before C2X" } */
+__extension__ _Float64x b
+  = 2.0F64x;
diff --git a/gcc/testsuite/gcc.dg/c2x-floatn-1.c b/gcc/testsuite/gcc.dg/c2x-floatn-1.c
new file mode 100644
index 000000000000..d9998496ec9b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-floatn-1.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -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 } */
+
+_Float32 a
+  = 1.0F32;
+_Float64 b
+  = 1.0F64;
+_Float32x c
+  = 1.0F32x;
+__extension__ _Float32 d
+  = 2.0F32;
+__extension__ _Float64 e
+  = 2.0F64;
+__extension__ _Float32x f
+  = 2.0F32x;
diff --git a/gcc/testsuite/gcc.dg/c2x-floatn-2.c b/gcc/testsuite/gcc.dg/c2x-floatn-2.c
new file mode 100644
index 000000000000..179364564d2f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-floatn-2.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+/* { dg-add-options float128 } */
+/* { dg-require-effective-target float128 } */
+
+_Float128 a
+  = 1.0F128;
+__extension__ _Float128 b
+  = 2.0F128;
diff --git a/gcc/testsuite/gcc.dg/c2x-floatn-3.c b/gcc/testsuite/gcc.dg/c2x-floatn-3.c
new file mode 100644
index 000000000000..9ac133ccfdbd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-floatn-3.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+/* { dg-add-options float16 } */
+/* { dg-require-effective-target float16 } */
+
+_Float16 a
+  = 1.0F16;
+__extension__ _Float16 b
+  = 2.0F16;
diff --git a/gcc/testsuite/gcc.dg/c2x-floatn-4.c b/gcc/testsuite/gcc.dg/c2x-floatn-4.c
new file mode 100644
index 000000000000..5d3ab24ac1cd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-floatn-4.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+/* { dg-add-options float64x } */
+/* { dg-require-effective-target float64x } */
+
+_Float64x a
+  = 1.0F64x;
+__extension__ _Float64x b
+  = 2.0F64x;
diff --git a/gcc/testsuite/gcc.dg/c2x-floatn-5.c b/gcc/testsuite/gcc.dg/c2x-floatn-5.c
new file mode 100644
index 000000000000..ea4e4bed458c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-floatn-5.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -Wc11-c2x-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 } */
+
+_Float32 a		/* { dg-warning "ISO C does not support the '_Float32' type before C2X" } */
+  = 1.0F32;		/* { dg-warning "non-standard suffix on floating constant before C2X" } */
+_Float64 b		/* { dg-warning "ISO C does not support the '_Float64' type before C2X" } */
+  = 1.0F64;		/* { dg-warning "non-standard suffix on floating constant before C2X" } */
+_Float32x c		/* { dg-warning "ISO C does not support the '_Float32x' type before C2X" } */
+  = 1.0F32x;		/* { dg-warning "non-standard suffix on floating constant before C2X" } */
+__extension__ _Float32 d
+  = 2.0F32;
+__extension__ _Float64 e
+  = 2.0F64;
+__extension__ _Float32x f
+  = 2.0F32x;
diff --git a/gcc/testsuite/gcc.dg/c2x-floatn-6.c b/gcc/testsuite/gcc.dg/c2x-floatn-6.c
new file mode 100644
index 000000000000..c982a11d1647
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-floatn-6.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -Wc11-c2x-compat" } */
+/* { dg-add-options float128 } */
+/* { dg-require-effective-target float128 } */
+
+_Float128 a		/* { dg-warning "ISO C does not support the '_Float128' type before C2X" } */
+  = 1.0F128;		/* { dg-warning "non-standard suffix on floating constant before C2X" } */
+__extension__ _Float128 b
+  = 2.0F128;
diff --git a/gcc/testsuite/gcc.dg/c2x-floatn-7.c b/gcc/testsuite/gcc.dg/c2x-floatn-7.c
new file mode 100644
index 000000000000..bf9b1ffba75a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-floatn-7.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -Wc11-c2x-compat" } */
+/* { dg-add-options float16 } */
+/* { dg-require-effective-target float16 } */
+
+_Float16 a		/* { dg-warning "ISO C does not support the '_Float16' type before C2X" } */
+  = 1.0F16;		/* { dg-warning "non-standard suffix on floating constant before C2X" } */
+__extension__ _Float16 b
+  = 2.0F16;
diff --git a/gcc/testsuite/gcc.dg/c2x-floatn-8.c b/gcc/testsuite/gcc.dg/c2x-floatn-8.c
new file mode 100644
index 000000000000..7174b6603298
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-floatn-8.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -Wc11-c2x-compat" } */
+/* { dg-add-options float64x } */
+/* { dg-require-effective-target float64x } */
+
+_Float64x a		/* { dg-warning "ISO C does not support the '_Float64x' type before C2X" } */
+  = 1.0F64x;		/* { dg-warning "non-standard suffix on floating constant before C2X" } */
+__extension__ _Float64x b
+  = 2.0F64x;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-06  6:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-06  6:51 [gcc r14-3731] c: Don't pedwarn on _FloatN{, x} or {f, F}N{, x} suffixes for C2X Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).