Greetings,

This old bug involved C++98 accepting hex floats without complaint.
I also split the error messages between C and C++ like in the recent PR 61389 patch.

Bootstrapped and tested clean on x86_64-linux.

OK?

libcpp/

2014-07-12  Edward Smith-Rowland  <3dw...@verizon.net>

        PR preprocessor/23827
        * init.c (lang_defaults[]): Set extended_identifiers to false for C++98.
        * expr.c (cpp_classify_number()): Make hexfloat pedward trigger
        for !extended_identifiers.  Split error message for C99 and C++11.


gcc/testsuite/

2014-07-12  Edward Smith-Rowland  <3dw...@verizon.net>

        PR preprocessor/23827
        * g++.dg/cpp/pr23827.C: New.

Index: libcpp/init.c
===================================================================
--- libcpp/init.c       (revision 212479)
+++ libcpp/init.c       (working copy)
@@ -102,7 +102,7 @@
   /* STDC99   */  { 1,  0,  1,   0,  0,  1,   1,   1,   0,   0,   0,    0,     
 0 },
   /* STDC11   */  { 1,  0,  1,   0,  1,  1,   1,   1,   1,   0,   0,    0,     
 0 },
   /* GNUCXX   */  { 0,  1,  1,   0,  0,  0,   1,   1,   0,   0,   0,    0,     
 0 },
-  /* CXX98    */  { 0,  1,  1,   0,  0,  1,   1,   1,   0,   0,   0,    0,     
 0 },
+  /* CXX98    */  { 0,  1,  0,   0,  0,  1,   1,   1,   0,   0,   0,    0,     
 0 },
   /* GNUCXX11 */  { 1,  1,  1,   0,  1,  0,   1,   1,   1,   1,   1,    0,     
 0 },
   /* CXX11    */  { 1,  1,  1,   0,  1,  1,   1,   1,   1,   1,   1,    0,     
 0 },
   /* GNUCXX1Y */  { 1,  1,  1,   0,  1,  0,   1,   1,   1,   1,   1,    1,     
 1 },
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c       (revision 212479)
+++ libcpp/expr.c       (working copy)
@@ -540,9 +540,16 @@
        SYNTAX_ERROR_AT (virtual_location,
                         "no digits in hexadecimal floating constant");
 
-      if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
-       cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
-                            "use of C99 hexadecimal floating constant");
+      if (radix == 16 && CPP_PEDANTIC (pfile)
+         && !CPP_OPTION (pfile, extended_numbers))
+       {
+         if (CPP_OPTION (pfile, cplusplus))
+           cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
+                                "use of C++11 hexadecimal floating constant");
+         else
+           cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
+                                "use of C99 hexadecimal floating constant");
+       }
 
       if (float_flag == AFTER_EXPON)
        {
Index: gcc/testsuite/g++.dg/cpp/pr23827.C
===================================================================
--- gcc/testsuite/g++.dg/cpp/pr23827.C  (revision 0)
+++ gcc/testsuite/g++.dg/cpp/pr23827.C  (working copy)
@@ -0,0 +1,22 @@
+// { dg-do run }
+// { dg-options "-std=c++98 -pedantic-errors" }
+
+#define f (
+#define l )
+#define str(x) #x
+#define xstr(x) str(x)
+
+/* C90 and C++: "0x1p+( 0x1p+)"; C99: "0x1p+f 0x1p+l" */
+const char *s = xstr(0x1p+f 0x1p+l);
+
+extern "C" void abort();
+extern "C" int strcmp(const char *, const char *);
+
+int
+main()
+{
+  if (strcmp (s, "0x1p+( 0x1p+)"))
+    abort();
+  else
+    return 0;
+}

Reply via email to