From patchwork Thu Aug 28 13:25:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ed Smith-Rowland <3dw4rd@verizon.net> X-Patchwork-Id: 383837 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 88BEA14011E for ; Thu, 28 Aug 2014 23:26:15 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=EBIhDXNgRekAJ57b4 CmyRZUSkTVDMzA5Jd+i5V8Jzgs9sduS1qYc8/qcaJS1yHAmztlZNVSe9rVNQs7io n/ds2/YQ/ahC3gaq6nosCb6IpIdnL6b+CTvw3/sWPC43dKpWFSRj9Nk7q3HF/Mcn sd2s10nX5p+6PMyivGve9UVDTw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=QhKWGXCZnhppP2fQx9FpXs2 Gxlw=; b=xZVgL0sQpqsLH5cpT90cRkvQhaqFFL+Ufz5/SWHY/4IB/hdZccP2m/8 58zjiTpp/0MPQZ8Q+DYmiY/dwdUg97IKarZuKks5R3t8UBUojRJTYIWHN49i+dyZ AXtyBl3PpT37E3+pi+/bXXfxThyoggjS9c8pUF6TSMqgon/QNRUE= Received: (qmail 29366 invoked by alias); 28 Aug 2014 13:25:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 29329 invoked by uid 89); 28 Aug 2014 13:25:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 3 recipients X-HELO: vms173009pub.verizon.net Received: from vms173009pub.verizon.net (HELO vms173009pub.verizon.net) (206.46.173.9) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 28 Aug 2014 13:25:41 +0000 Received: from [192.168.1.4] ([unknown] [173.69.187.187]) by vms173009.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0NB0001WXQM7R910@vms173009.mailsrvcs.net>; Thu, 28 Aug 2014 08:25:20 -0500 (CDT) Message-id: <53FF2DC0.7050307@verizon.net> Date: Thu, 28 Aug 2014 09:25:20 -0400 From: Ed Smith-Rowland <3dw4rd@verizon.net> User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-version: 1.0 To: Jason Merrill , gcc-patches , jsm28@gcc.gnu.org, pinskia@gcc.gnu.org Subject: Re: [PATCH, CPP/23827] standard C++ should not have hex float preprocessing tokens References: <53FDF170.7080208@verizon.net> <53FE3434.506@redhat.com> In-reply-to: <53FE3434.506@redhat.com> Content-type: multipart/mixed; boundary=------------090503030805010306090909 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 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. 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. */ +}