@@ -653,14 +653,14 @@ c_cpp_builtins (cpp_reader *pfile)
builtin_define_with_int_value ("__DEC_EVAL_METHOD__",
TARGET_DEC_EVAL_METHOD);
- builtin_define_float_constants ("FLT", "F", "%s", "F", float_type_node);
+ builtin_define_float_constants ("FLT", "F", NULL, "F", float_type_node);
/* 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)", "",
+ builtin_define_float_constants ("DBL", "L", "double", "",
double_type_node);
- builtin_define_float_constants ("LDBL", "L", "%s", "L",
+ builtin_define_float_constants ("LDBL", "L", NULL, "L",
long_double_type_node);
/* For decfloat.h. */
@@ -983,7 +983,12 @@ builtin_define_with_hex_fp_value (const char *macro,
struct cpp_hashnode *node;
if (lazy_hex_fp_value_count == 0)
cpp_get_callbacks (parse_in)->user_builtin_macro = lazy_hex_fp_value;
- sprintf (buf2, fp_cast, "1.1");
+ if (fp_cast == NULL)
+ sprintf (buf2, "1.1");
+ else if (c_dialect_cxx ())
+ sprintf (buf2, "static_cast<%s>(1.1)", fp_cast);
+ else
+ sprintf (buf2, "((%s)1.1)", fp_cast);
sprintf (buf1, "%s=%s", macro, buf2);
cpp_define (parse_in, buf1);
node = C_CPP_HASHNODE (get_identifier (macro));
@@ -1014,11 +1019,14 @@ builtin_define_with_hex_fp_value (const char *macro,
real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str), digits, 0,
TYPE_MODE (type));
- /* Assemble the macro in the following fashion
- macro = fp_cast [dec_str fp_suffix] */
- sprintf (buf1, "%s%s", dec_str, fp_suffix);
- sprintf (buf2, fp_cast, buf1);
- sprintf (buf1, "%s=%s", macro, buf2);
+ /* Avoid issues with -Wold-style-cast if FP_CAST is specified. */
+ if (fp_cast == NULL)
+ sprintf (buf1, "%s=%s%s", macro, dec_str, fp_suffix);
+ else if (c_dialect_cxx ())
+ sprintf (buf1, "%s=static_cast<%s>(%s%s)", macro, fp_cast, dec_str,
+ fp_suffix);
+ else
+ sprintf (buf1, "%s=((%s)%s%s)", macro, fp_cast, dec_str, fp_suffix);
cpp_define (parse_in, buf1);
}
new file mode 100644
@@ -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__;
+}