From patchwork Wed Nov 10 13:22:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Froyd X-Patchwork-Id: 70635 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]) by ozlabs.org (Postfix) with SMTP id 74239B70E7 for ; Thu, 11 Nov 2010 00:22:30 +1100 (EST) Received: (qmail 3044 invoked by alias); 10 Nov 2010 13:22:28 -0000 Received: (qmail 3035 invoked by uid 22791); 10 Nov 2010 13:22:28 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 10 Nov 2010 13:22:23 +0000 Received: (qmail 29169 invoked from network); 10 Nov 2010 13:22:21 -0000 Received: from unknown (HELO codesourcery.com) (froydnj@127.0.0.2) by mail.codesourcery.com with ESMTPA; 10 Nov 2010 13:22:21 -0000 Date: Wed, 10 Nov 2010 08:22:18 -0500 From: Nathan Froyd To: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] fix PR 45038, bad interaction between __DBL_MIN__ and -Wold-style-cast Message-ID: <20101110132218.GK7991@nightcrawler> References: <20101109221019.GI7991@nightcrawler> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20101109221019.GI7991@nightcrawler> User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes 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 On Tue, Nov 09, 2010 at 05:10:20PM -0500, Nathan Froyd wrote: > Builtin double-precision floating-point constants defined by the > preprocessor get defined as `((double)VAL)'; this style causes problems > with -Wold-style-cast. The patch below tweaks the definition of such > constants to use static_cast when compiling for C++. My previous patch was overly complicated. This one is much simpler. I used a function style cast as suggested by Gabriel, but I am unsure of whether that is preferred over static_cast. Tested on x86_64-unknown-linux-gnu. OK to commit? -Nathan diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c index 7b5a14d..ca77964 100644 --- a/gcc/c-family/c-cppbuiltin.c +++ b/gcc/c-family/c-cppbuiltin.c @@ -657,9 +657,13 @@ c_cpp_builtins (cpp_reader *pfile) /* Cast the double precision constants. This is needed when single precision constants are specified or when pragma FLOAT_CONST_DECIMAL64 is used. The correct result is computed by the compiler when using - macros that include a cast. */ - builtin_define_float_constants ("DBL", "L", "((double)%s)", "", - double_type_node); + macros that include a cast. We use a different cast for C++ to avoid + problems with -Wold-style-cast. */ + builtin_define_float_constants ("DBL", "L", + (c_dialect_cxx () + ? "double(%s)" + : "((double)%s)"), + "", double_type_node); builtin_define_float_constants ("LDBL", "L", "%s", "L", long_double_type_node); diff --git a/gcc/testsuite/g++.dg/pr45038.C b/gcc/testsuite/g++.dg/pr45038.C new file mode 100644 index 0000000..57c0c44 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr45038.C @@ -0,0 +1,9 @@ +// PR preprocessor/45038 +// { dg-do compile } +// { dg-options "-Werror -Wold-style-cast" } + +double f(void) +{ + // We used to produce old-style casts for this. + return __DBL_MIN__; +}