re PR preprocessor/45038 (__DBL_MIN__ result in old-style-cast)
authorNathan Froyd <froydnj@codesourcery.com>
Mon, 15 Nov 2010 15:24:31 +0000 (15:24 +0000)
committerNathan Froyd <froydnj@gcc.gnu.org>
Mon, 15 Nov 2010 15:24:31 +0000 (15:24 +0000)
gcc/c-family/
PR preprocessor/45038
* c-cppbuiltin.c (c_cpp_builtins): Use different format for C++
dialects.

gcc/testsuite/
PR preprocessor/45038
* g++.dg/pr45038.C: New test.

From-SVN: r166756

gcc/c-family/ChangeLog
gcc/c-family/c-cppbuiltin.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/pr45038.C [new file with mode: 0644]

index bb0472e2957f427e28a8d9e29689a738edd132e8..4e31d6a1e18456c9d96aa7b29c6e2bd9a08448f1 100644 (file)
@@ -1,3 +1,9 @@
+2010-11-15  Nathan Froyd  <froydnj@codesourcery.com>
+
+       PR preprocessor/45038
+       * c-cppbuiltin.c (c_cpp_builtins): Use different format for C++
+       dialects.
+
 2010-11-12  Joseph Myers  <joseph@codesourcery.com>
 
        * c-common.h (c_family_lang_mask): Declare.
index 7b5a14dda11afe9ceb08264e6f1b5ea2e86bcdcb..ca779648b20479cd2e82877ce1c009923225d676 100644 (file)
@@ -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);
 
index bad83cd98364cbc71385bbe0e8cee7366bc27476..79ec4a98a64d352e5c5490aad655cbe1cef7530d 100644 (file)
@@ -1,3 +1,8 @@
+2010-11-15  Nathan Froyd  <froydnj@codesourcery.com>
+
+       PR preprocessor/45038
+       * g++.dg/pr45038.C: New test.
+
 2010-11-15  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/46467
diff --git a/gcc/testsuite/g++.dg/pr45038.C b/gcc/testsuite/g++.dg/pr45038.C
new file mode 100644 (file)
index 0000000..57c0c44
--- /dev/null
@@ -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__;
+}