A new option is added to warn if floating point literals have non-standard
suffices (currently Q and W) in pedantic mode. The option is ON by default.
The negative form `-Wno-non-standard-suffix` is expected to be used typically,
as is done for GCC itself and a few tests that otherwise would issue warnings.

        PR c/92826

gcc/c-family/ChangeLog:

        * c-lex.cc (interpret_float): Check flag before warning.
        * c.opt: Add new flag.

gcc/ChangeLog:

        * configure: Regenerate.
        * configure.ac: Turn off flag for compiling GCC.
        * doc/invoke.texi: Document the new flag.

gcc/testsuite/ChangeLog:

        * g++.dg/cpp/limits.C: Turn off flag.
        * g++.dg/cpp1y/lambda-generic-x.C: Turn off flag.
        * g++.dg/warn/huge-val1.C: Turn off flag.
        * c-c++-common/pr92826.c: Move test...
        * c-c++-common/Wno-non-standard-suffix.c: ... here.
---
 gcc/c-family/c-lex.cc                         |  4 +--
 gcc/c-family/c.opt                            |  4 +++
 gcc/configure                                 | 25 ++++++++++---------
 gcc/configure.ac                              |  3 ++-
 gcc/doc/invoke.texi                           |  7 ++++++
 .../c-c++-common/Wno-non-standard-suffix.c    |  6 +++++
 gcc/testsuite/c-c++-common/pr92826.c          |  6 -----
 gcc/testsuite/g++.dg/cpp/limits.C             |  2 +-
 gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C |  2 +-
 gcc/testsuite/g++.dg/warn/huge-val1.C         |  2 +-
 10 files changed, 37 insertions(+), 24 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/Wno-non-standard-suffix.c
 delete mode 100644 gcc/testsuite/c-c++-common/pr92826.c

diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc
index 8065e825e7f..14db96c2d27 100644
--- a/gcc/c-family/c-lex.cc
+++ b/gcc/c-family/c-lex.cc
@@ -1262,8 +1262,8 @@ interpret_float (const cpp_token *token, unsigned int 
flags,
 
            return error_mark_node;
          }
-       else
-         pedwarn (token->src_loc, OPT_Wpedantic,
+       else if (warn_nonstandard_suffix)
+         pedwarn (token->src_loc, OPT_Wnon_standard_suffix,
                   "non-standard suffix on floating constant");
 
        type = c_common_type_for_mode (mode, 0);
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 75b6531860e..d033b8218b9 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1098,6 +1098,10 @@ Wnoexcept-type
 C++ ObjC++ Warning Var(warn_noexcept_type) LangEnabledBy(C++ ObjC++,Wabi || 
Wc++17-compat)
 Warn if C++17 noexcept function type will change the mangled name of a symbol.
 
+Wnon-standard-suffix
+C C++ Var(warn_nonstandard_suffix) Warning EnabledBy(Wpedantic)
+Enable pedantic warnings on non-standard suffices for floating point 
constants, e.g., as used in <quadmath.h>.
+
 Wnon-template-friend
 C++ ObjC++ Var(warn_nontemplate_friend) Init(1) Warning
 Warn when non-templatized friend functions are declared within a template.
diff --git a/gcc/configure b/gcc/configure
index 776b0628c60..2b28063ecea 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -7172,6 +7172,7 @@ fi
 # * 'long long'
 # * variadic macros
 # * overlong strings
+# * non-standard floating suffices
 # So, we only use -pedantic if we can disable those warnings.
 
 # In stage 1, disable -Wformat warnings from old GCCs about new % codes
@@ -7425,13 +7426,13 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 # Do the check with the no- prefix removed from the warning options
 # since gcc silently accepts any -Wno-* option on purpose
 if test "$GXX" = yes; then :
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX supports 
-pedantic -Wlong-long -Wvariadic-macros -Woverlength-strings" >&5
-$as_echo_n "checking whether $CXX supports -pedantic -Wlong-long 
-Wvariadic-macros -Woverlength-strings... " >&6; }
-if 
${acx_cv_prog_cc_pedantic__Wlong_long__Wvariadic_macros__Woverlength_strings+:} 
false; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX supports 
-pedantic -Wlong-long -Wnon-standard-suffix -Wvariadic-macros 
-Woverlength-strings" >&5
+$as_echo_n "checking whether $CXX supports -pedantic -Wlong-long 
-Wnon-standard-suffix -Wvariadic-macros -Woverlength-strings... " >&6; }
+if 
${acx_cv_prog_cc_pedantic__Wlong_long__Wnon_standard_suffix__Wvariadic_macros__Woverlength_strings+:}
 false; then :
   $as_echo_n "(cached) " >&6
 else
   save_CXXFLAGS="$CXXFLAGS"
-CXXFLAGS="-pedantic -Wlong-long -Wvariadic-macros -Woverlength-strings"
+CXXFLAGS="-pedantic -Wlong-long -Wnon-standard-suffix -Wvariadic-macros 
-Woverlength-strings"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -7444,17 +7445,17 @@ main ()
 }
 _ACEOF
 if ac_fn_cxx_try_compile "$LINENO"; then :
-  
acx_cv_prog_cc_pedantic__Wlong_long__Wvariadic_macros__Woverlength_strings=yes
+  
acx_cv_prog_cc_pedantic__Wlong_long__Wnon_standard_suffix__Wvariadic_macros__Woverlength_strings=yes
 else
-  acx_cv_prog_cc_pedantic__Wlong_long__Wvariadic_macros__Woverlength_strings=no
+  
acx_cv_prog_cc_pedantic__Wlong_long__Wnon_standard_suffix__Wvariadic_macros__Woverlength_strings=no
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 CXXFLAGS="$save_CXXFLAGS"
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$acx_cv_prog_cc_pedantic__Wlong_long__Wvariadic_macros__Woverlength_strings" >&5
-$as_echo 
"$acx_cv_prog_cc_pedantic__Wlong_long__Wvariadic_macros__Woverlength_strings" 
>&6; }
-if test 
$acx_cv_prog_cc_pedantic__Wlong_long__Wvariadic_macros__Woverlength_strings = 
yes; then :
-  strict_warn="$strict_warn${strict_warn:+ }-pedantic -Wno-long-long 
-Wno-variadic-macros -Wno-overlength-strings"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$acx_cv_prog_cc_pedantic__Wlong_long__Wnon_standard_suffix__Wvariadic_macros__Woverlength_strings"
 >&5
+$as_echo 
"$acx_cv_prog_cc_pedantic__Wlong_long__Wnon_standard_suffix__Wvariadic_macros__Woverlength_strings"
 >&6; }
+if test 
$acx_cv_prog_cc_pedantic__Wlong_long__Wnon_standard_suffix__Wvariadic_macros__Woverlength_strings
 = yes; then :
+  strict_warn="$strict_warn${strict_warn:+ }-pedantic -Wno-long-long 
-Wno-non-standard-suffix -Wno-variadic-macros -Wno-overlength-strings"
 fi
 
 fi
@@ -21520,7 +21521,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 21523 "configure"
+#line 21524 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -21626,7 +21627,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 21629 "configure"
+#line 21630 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index b6db9edfc83..6ec30b2b668 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -601,6 +601,7 @@ AC_SUBST(aliasing_flags)
 # * 'long long'
 # * variadic macros
 # * overlong strings
+# * non-standard floating suffices
 # So, we only use -pedantic if we can disable those warnings.
 
 # In stage 1, disable -Wformat warnings from old GCCs about new % codes
@@ -622,7 +623,7 @@ ACX_PROG_CXX_WARNING_OPTS(
 ACX_PROG_CC_WARNING_OPTS(
        m4_quote(m4_do([-Wold-style-definition -Wc++-compat])), [c_strict_warn])
 ACX_PROG_CXX_WARNING_ALMOST_PEDANTIC(
-       m4_quote(m4_do([-Wno-long-long -Wno-variadic-macros ], 
+       m4_quote(m4_do([-Wno-long-long -Wno-non-standard-suffix 
-Wno-variadic-macros ],
                       [-Wno-overlength-strings])), [strict_warn])
 ACX_PROG_CXX_WARNINGS_ARE_ERRORS([manual], [strict_warn])
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 0150ad08879..59d327a9d69 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -397,6 +397,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wmissing-include-dirs  -Wmissing-noreturn  -Wmusttail-local-addr
 -Wmaybe-musttail-local-addr  -Wno-missing-profile
 -Wno-multichar  -Wmultistatement-macros  -Wnonnull  -Wnonnull-compare
+-Wnon-standard-suffix
 -Wnormalized=@r{[}none@r{|}id@r{|}nfc@r{|}nfkc@r{]}
 -Wnull-dereference  -Wno-odr
 -Wopenacc-parallelism
@@ -7572,6 +7573,12 @@ if (c)
 
 This warning is enabled by @option{-Wall} in C and C++.
 
+@opindex Wnon-standard-suffix
+@opindex Wno-non-standard-suffix
+@item -Wnon-standard-suffix
+Issue a warning for non-standard floating point suffices @code{Q} and @code{W}
+in pedantic mode.  The warning is enabled by @option{-Wpedantic} in C and C++.
+
 @opindex Wparentheses
 @opindex Wno-parentheses
 @item -Wparentheses
diff --git a/gcc/testsuite/c-c++-common/Wno-non-standard-suffix.c 
b/gcc/testsuite/c-c++-common/Wno-non-standard-suffix.c
new file mode 100644
index 00000000000..a87b602f97d
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wno-non-standard-suffix.c
@@ -0,0 +1,6 @@
+/* Test turning non-standard suffix warnings off. */
+/* { dg-require-effective-target __float128 } */
+/* { dg-options "-pedantic -Wno-non-standard-suffix" } */
+/* { dg-add-options __float128 } */
+
+__float128 a = 1.0q;
diff --git a/gcc/testsuite/c-c++-common/pr92826.c 
b/gcc/testsuite/c-c++-common/pr92826.c
deleted file mode 100644
index ea2e20c6331..00000000000
--- a/gcc/testsuite/c-c++-common/pr92826.c
+++ /dev/null
@@ -1,6 +0,0 @@
-/* { dg-options "-pedantic" } */
-
-int main()
-{
-    return 1.0Q > 0.1; /* { dg-warning "12: non-standard suffix on floating 
constant .-Wpedantic" } */
-}
diff --git a/gcc/testsuite/g++.dg/cpp/limits.C 
b/gcc/testsuite/g++.dg/cpp/limits.C
index 5824e019312..14ef405cbb2 100644
--- a/gcc/testsuite/g++.dg/cpp/limits.C
+++ b/gcc/testsuite/g++.dg/cpp/limits.C
@@ -1,4 +1,4 @@
-// { dg-options "-pedantic" }
+// { dg-options "-pedantic -Wno-non-standard-suffix" }
 // { dg-do compile }
 
 #include <limits>
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C 
b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C
index 723512f71f5..cf94b88bf43 100644
--- a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C
+++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C
@@ -1,6 +1,6 @@
 // Explicit generic lambda test from N3690 5.1.2.5
 // { dg-do compile { target c++14 } }
-// { dg-options "-Wpedantic" }
+// { dg-options "-Wpedantic -Wno-non-standard-suffix" }
 // { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } }
 
 #include <iostream>
diff --git a/gcc/testsuite/g++.dg/warn/huge-val1.C 
b/gcc/testsuite/g++.dg/warn/huge-val1.C
index c480cf32f35..87a21b9b97f 100644
--- a/gcc/testsuite/g++.dg/warn/huge-val1.C
+++ b/gcc/testsuite/g++.dg/warn/huge-val1.C
@@ -1,7 +1,7 @@
 // PR c++/23139: HUGE_VAL definition should be accepted with -pedantic.
 // Origin: Joseph Myers <jos...@codesourcery.com>
 // { dg-do link }
-// { dg-options "-pedantic-errors" }
+// { dg-options "-pedantic-errors -Wno-non-standard-suffix" }
 // { dg-skip-if "requires hosted libstdc++ for cmath" { ! hostedlib } }
 
 #include <math.h>
-- 
2.34.1

Reply via email to