* [PATCH, CPP/23827] standard C++ should not have hex float preprocessing tokens
@ 2014-08-27 14:56 Ed Smith-Rowland
2014-08-27 19:40 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Ed Smith-Rowland @ 2014-08-27 14:56 UTC (permalink / raw)
To: gcc-patches, jsm28, Jason Merrill, pinskia
[-- Attachment #1: Type: text/plain, Size: 243 bytes --]
This old one says the C++98 ANSI doesn't have hex float literals and
should error gracefully.
Fixed by changing a language feature flag as suggested by the audit
trail and by adding an error message.
Built and tested on x86_64-linux.
OK?
[-- Attachment #2: CL_pr23827 --]
[-- Type: text/plain, Size: 697 bytes --]
libcpp/
2014-08-27 Edward Smith-Rowland <3dw4rd@verizon.net>
PR cpp/23827 - standard C++ should not have hex float preprocessor
tokens
* libcpp/init.c (lang_flags): Change CXX98 flag for extended numbers
from 1 to 0.
* libcpp/expr.c (cpp_classify_number): Weite error message for improper
use of hex floating literal.
gcc/testsuite/
2014-08-27 Edward Smith-Rowland <3dw4rd@verizon.net>
PR cpp/23827 - standard C++ should not have hex float preprocessor
tokens
* g++.dg/cpp/pr23827_cxx11.C: New.
* g++.dg/cpp/pr23827_cxx98.C: New.
* g++.dg/cpp/pr23827_cxx98_neg.C: New.
* gcc.dg/cpp/pr23827_c90.c: New.
* gcc.dg/cpp/pr23827_c90_neg.c: New.
* gcc.dg/cpp/pr23827_c99.c: New.
[-- Attachment #3: patch_pr23827_3 --]
[-- Type: text/plain, Size: 5670 bytes --]
Index: libcpp/init.c
===================================================================
--- libcpp/init.c (revision 214556)
+++ libcpp/init.c (working copy)
@@ -103,7 +103,7 @@
/* STDC99 */ { 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
/* STDC11 */ { 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
/* GNUCXX */ { 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 },
- /* CXX98 */ { 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
+ /* CXX98 */ { 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
/* GNUCXX11 */ { 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0 },
/* CXX11 */ { 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1 },
/* GNUCXX14 */ { 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0 },
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c (revision 214556)
+++ 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_cxx11.C
===================================================================
--- gcc/testsuite/g++.dg/cpp/pr23827_cxx11.C (revision 0)
+++ gcc/testsuite/g++.dg/cpp/pr23827_cxx11.C (working copy)
@@ -0,0 +1,23 @@
+// { dg-do run { target c++11 } }
+// { dg-options "-pedantic-errors" }
+
+#define f (
+#define l )
+#define str(x) #x
+#define xstr(x) str(x)
+
+// C90 and C++98: "0x1p+( 0x1p+)"
+// C99 and C++11: "0x1p+f 0x1p+l"
+const char *s = xstr(0x1p+f 0x1p+l);
+
+extern "C" void abort (void);
+extern "C" int strcmp (const char *, const char *);
+
+int
+main()
+{
+ if (strcmp (s, "0x1p+( 0x1p+)"))
+ return 0; // Correct C99 and C++11 behavior.
+ else
+ abort (); // Correct C90 and C++ behavior.
+}
Index: gcc/testsuite/g++.dg/cpp/pr23827_cxx98.C
===================================================================
--- gcc/testsuite/g++.dg/cpp/pr23827_cxx98.C (revision 0)
+++ gcc/testsuite/g++.dg/cpp/pr23827_cxx98.C (working copy)
@@ -0,0 +1,23 @@
+// { dg-do run { target c++98_only } }
+// { dg-options "-ansi -pedantic-errors" }
+
+#define f (
+#define l )
+#define str(x) #x
+#define xstr(x) str(x)
+
+// C90 and C++98: "0x1p+( 0x1p+)"
+// C99 and C++11: "0x1p+f 0x1p+l"
+const char *s = xstr(0x1p+f 0x1p+l);
+
+extern "C" void abort (void);
+extern "C" int strcmp (const char *, const char *);
+
+int
+main()
+{
+ if (strcmp (s, "0x1p+( 0x1p+)"))
+ abort (); // Correct C99 and C++11 behavior.
+ else
+ return 0; // Correct C90 and C++ behavior.
+}
Index: gcc/testsuite/g++.dg/cpp/pr23827_cxx98_neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp/pr23827_cxx98_neg.C (revision 0)
+++ gcc/testsuite/g++.dg/cpp/pr23827_cxx98_neg.C (working copy)
@@ -0,0 +1,4 @@
+// { dg-do compile { target c++98_only } }
+/* { dg-options "-ansi -pedantic-errors" } */
+
+double x = 0x3.1415babep0; // { dg-error "use of C..11 hexadecimal floating constant" }
Index: gcc/testsuite/gcc.dg/cpp/pr23827_c90.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/pr23827_c90.c (revision 0)
+++ gcc/testsuite/gcc.dg/cpp/pr23827_c90.c (working copy)
@@ -0,0 +1,23 @@
+/* { dg-do run } */
+/* { dg-options "-std=c90 -pedantic-errors" } */
+
+#define f (
+#define l )
+#define str(x) #x
+#define xstr(x) str(x)
+
+/* C90 and C++98: "0x1p+( 0x1p+)" */
+/* C99 and C++11: "0x1p+f 0x1p+l" */
+const char *s = xstr(0x1p+f 0x1p+l);
+
+void abort (void);
+int strcmp (const char *, const char *);
+
+int
+main()
+{
+ if (strcmp (s, "0x1p+( 0x1p+)"))
+ abort (); /* Correct C99 and C++11 behavior. */
+ else
+ return 0; /* Correct C90 and C++ behavior. */
+}
Index: gcc/testsuite/gcc.dg/cpp/pr23827_c90_neg.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/pr23827_c90_neg.c (revision 0)
+++ gcc/testsuite/gcc.dg/cpp/pr23827_c90_neg.c (working copy)
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c90 -pedantic-errors" } */
+
+double x = 0x3.1415babep0; /* { dg-error "use of C99 hexadecimal floating constant" } */
Index: gcc/testsuite/gcc.dg/cpp/pr23827_c99.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/pr23827_c99.c (revision 0)
+++ gcc/testsuite/gcc.dg/cpp/pr23827_c99.c (working copy)
@@ -0,0 +1,23 @@
+/* { dg-do run { target c++11 } } */
+/* { dg-options "-pedantic-errors" } */
+
+#define f (
+#define l )
+#define str(x) #x
+#define xstr(x) str(x)
+
+/* C90 and C++98: "0x1p+( 0x1p+)" */
+/* C99 and C++11: "0x1p+f 0x1p+l" */
+const char *s = xstr(0x1p+f 0x1p+l);
+
+void abort (void);
+int strcmp (const char *, const char *);
+
+int
+main()
+{
+ if (strcmp (s, "0x1p+( 0x1p+)"))
+ return 0; /* Correct C99 and C++11 behavior. */
+ else
+ abort (); /* Correct C90 and C++ behavior. */
+}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH, CPP/23827] standard C++ should not have hex float preprocessing tokens
2014-08-27 14:56 [PATCH, CPP/23827] standard C++ should not have hex float preprocessing tokens Ed Smith-Rowland
@ 2014-08-27 19:40 ` Jason Merrill
2014-08-28 13:25 ` Ed Smith-Rowland
0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2014-08-27 19:40 UTC (permalink / raw)
To: Ed Smith-Rowland, gcc-patches, jsm28, pinskia
OK.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH, CPP/23827] standard C++ should not have hex float preprocessing tokens
2014-08-27 19:40 ` Jason Merrill
@ 2014-08-28 13:25 ` Ed Smith-Rowland
2014-08-28 13:41 ` Marc Glisse
0 siblings, 1 reply; 6+ messages in thread
From: Ed Smith-Rowland @ 2014-08-28 13:25 UTC (permalink / raw)
To: Jason Merrill, gcc-patches, jsm28, pinskia
[-- Attachment #1: Type: text/plain, Size: 171 bytes --]
On 08/27/2014 03:40 PM, Jason Merrill wrote:
> OK.
>
> Jason
>
Is this OK for 4.9 also?
It builds and tests clean on x86_64-linux.
Attached slightly modified patch.
Ed
[-- Attachment #2: CL_pr23827 --]
[-- Type: text/plain, Size: 698 bytes --]
libcpp/
2014-08-28 Edward Smith-Rowland <3dw4rd@verizon.net>
PR cpp/23827 - standard C++ should not have hex float preprocessor
tokens
* libcpp/init.c (lang_flags): Change CXX98 flag for extended numbers
from 1 to 0.
* libcpp/expr.c (cpp_classify_number): Weite error message for improper
use of hex floating literal.
gcc/testsuite/
2014-08-28 Edward Smith-Rowland <3dw4rd@verizon.net>
PR cpp/23827 - standard C++ should not have hex float preprocessor
tokens
* g++.dg/cpp/pr23827_cxx11.C: New.
* g++.dg/cpp/pr23827_cxx98.C: New.
* g++.dg/cpp/pr23827_cxx98_neg.C: New.
* gcc.dg/cpp/pr23827_c90.c: New.
* gcc.dg/cpp/pr23827_c90_neg.c: New.
* gcc.dg/cpp/pr23827_c99.c: New.
[-- Attachment #3: patch_pr23827_4 --]
[-- Type: text/plain, Size: 5652 bytes --]
Index: libcpp/init.c
===================================================================
--- libcpp/init.c (revision 214616)
+++ libcpp/init.c (working copy)
@@ -98,7 +98,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 214616)
+++ 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_cxx11.C
===================================================================
--- gcc/testsuite/g++.dg/cpp/pr23827_cxx11.C (revision 0)
+++ gcc/testsuite/g++.dg/cpp/pr23827_cxx11.C (working copy)
@@ -0,0 +1,23 @@
+// { dg-do run { target c++11 } }
+// { dg-options "-pedantic-errors" }
+
+#define f (
+#define l )
+#define str(x) #x
+#define xstr(x) str(x)
+
+// C90 and C++98: "0x1p+( 0x1p+)"
+// C99 and C++11: "0x1p+f 0x1p+l"
+const char *s = xstr(0x1p+f 0x1p+l);
+
+extern "C" void abort (void);
+extern "C" int strcmp (const char *, const char *);
+
+int
+main()
+{
+ if (strcmp (s, "0x1p+( 0x1p+)"))
+ return 0; // Correct C99 and C++11 behavior.
+ else
+ abort (); // Correct C90 and C++ behavior.
+}
Index: gcc/testsuite/g++.dg/cpp/pr23827_cxx98.C
===================================================================
--- gcc/testsuite/g++.dg/cpp/pr23827_cxx98.C (revision 0)
+++ gcc/testsuite/g++.dg/cpp/pr23827_cxx98.C (working copy)
@@ -0,0 +1,23 @@
+// { dg-do run { target c++98_only } }
+// { dg-options "-ansi -pedantic-errors" }
+
+#define f (
+#define l )
+#define str(x) #x
+#define xstr(x) str(x)
+
+// C90 and C++98: "0x1p+( 0x1p+)"
+// C99 and C++11: "0x1p+f 0x1p+l"
+const char *s = xstr(0x1p+f 0x1p+l);
+
+extern "C" void abort (void);
+extern "C" int strcmp (const char *, const char *);
+
+int
+main()
+{
+ if (strcmp (s, "0x1p+( 0x1p+)"))
+ abort (); // Correct C99 and C++11 behavior.
+ else
+ return 0; // Correct C90 and C++ behavior.
+}
Index: gcc/testsuite/g++.dg/cpp/pr23827_cxx98_neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp/pr23827_cxx98_neg.C (revision 0)
+++ gcc/testsuite/g++.dg/cpp/pr23827_cxx98_neg.C (working copy)
@@ -0,0 +1,4 @@
+// { dg-do compile { target c++98_only } }
+/* { dg-options "-ansi -pedantic-errors" } */
+
+double x = 0x3.1415babep0; // { dg-error "use of C..11 hexadecimal floating constant" }
Index: gcc/testsuite/gcc.dg/cpp/pr23827_c90.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/pr23827_c90.c (revision 0)
+++ gcc/testsuite/gcc.dg/cpp/pr23827_c90.c (working copy)
@@ -0,0 +1,23 @@
+/* { dg-do run } */
+/* { dg-options "-std=c90 -pedantic-errors" } */
+
+#define f (
+#define l )
+#define str(x) #x
+#define xstr(x) str(x)
+
+/* C90 and C++98: "0x1p+( 0x1p+)" */
+/* C99 and C++11: "0x1p+f 0x1p+l" */
+const char *s = xstr(0x1p+f 0x1p+l);
+
+void abort (void);
+int strcmp (const char *, const char *);
+
+int
+main()
+{
+ if (strcmp (s, "0x1p+( 0x1p+)"))
+ abort (); /* Correct C99 and C++11 behavior. */
+ else
+ return 0; /* Correct C90 and C++ behavior. */
+}
Index: gcc/testsuite/gcc.dg/cpp/pr23827_c90_neg.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/pr23827_c90_neg.c (revision 0)
+++ gcc/testsuite/gcc.dg/cpp/pr23827_c90_neg.c (working copy)
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c90 -pedantic-errors" } */
+
+double x = 0x3.1415babep0; /* { dg-error "use of C99 hexadecimal floating constant" } */
Index: gcc/testsuite/gcc.dg/cpp/pr23827_c99.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/pr23827_c99.c (revision 0)
+++ gcc/testsuite/gcc.dg/cpp/pr23827_c99.c (working copy)
@@ -0,0 +1,23 @@
+/* { dg-do run { target c++11 } } */
+/* { dg-options "-pedantic-errors" } */
+
+#define f (
+#define l )
+#define str(x) #x
+#define xstr(x) str(x)
+
+/* C90 and C++98: "0x1p+( 0x1p+)" */
+/* C99 and C++11: "0x1p+f 0x1p+l" */
+const char *s = xstr(0x1p+f 0x1p+l);
+
+void abort (void);
+int strcmp (const char *, const char *);
+
+int
+main()
+{
+ if (strcmp (s, "0x1p+( 0x1p+)"))
+ return 0; /* Correct C99 and C++11 behavior. */
+ else
+ abort (); /* Correct C90 and C++ behavior. */
+}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH, CPP/23827] standard C++ should not have hex float preprocessing tokens
2014-08-28 13:25 ` Ed Smith-Rowland
@ 2014-08-28 13:41 ` Marc Glisse
2014-08-28 13:48 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Marc Glisse @ 2014-08-28 13:41 UTC (permalink / raw)
To: Ed Smith-Rowland; +Cc: Jason Merrill, gcc-patches, jsm28, pinskia
On Thu, 28 Aug 2014, Ed Smith-Rowland wrote:
> Is this OK for 4.9 also?
> It builds and tests clean on x86_64-linux.
>
> Attached slightly modified patch.
In my opinion it is not appropriate for a backport, no. If someone was
using hex floats with -std=c++98 with 4.9.1, it should still work with
4.9.2, I only expect to have to fix such things when moving to 5.0.
--
Marc Glisse
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH, CPP/23827] standard C++ should not have hex float preprocessing tokens
2014-08-28 13:41 ` Marc Glisse
@ 2014-08-28 13:48 ` Jason Merrill
2014-08-28 14:27 ` Ed Smith-Rowland
0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2014-08-28 13:48 UTC (permalink / raw)
To: Ed Smith-Rowland; +Cc: gcc-patches, jsm28, pinskia
On 08/28/2014 09:41 AM, Marc Glisse wrote:
> In my opinion it is not appropriate for a backport, no. If someone was
> using hex floats with -std=c++98 with 4.9.1, it should still work with
> 4.9.2, I only expect to have to fix such things when moving to 5.0.
Agreed.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH, CPP/23827] standard C++ should not have hex float preprocessing tokens
2014-08-28 13:48 ` Jason Merrill
@ 2014-08-28 14:27 ` Ed Smith-Rowland
0 siblings, 0 replies; 6+ messages in thread
From: Ed Smith-Rowland @ 2014-08-28 14:27 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches, jsm28, pinskia
On 08/28/2014 09:47 AM, Jason Merrill wrote:
> On 08/28/2014 09:41 AM, Marc Glisse wrote:
>> In my opinion it is not appropriate for a backport, no. If someone was
>> using hex floats with -std=c++98 with 4.9.1, it should still work with
>> 4.9.2, I only expect to have to fix such things when moving to 5.0.
>
> Agreed.
>
> Jason
>
>
>
OK, I understand. Makes sense.
It is a capability change not really just a bugfix per se.
On that note is it worth a sentence in Changes?
Ed
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-08-28 14:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-27 14:56 [PATCH, CPP/23827] standard C++ should not have hex float preprocessing tokens Ed Smith-Rowland
2014-08-27 19:40 ` Jason Merrill
2014-08-28 13:25 ` Ed Smith-Rowland
2014-08-28 13:41 ` Marc Glisse
2014-08-28 13:48 ` Jason Merrill
2014-08-28 14:27 ` Ed Smith-Rowland
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).