Commit a73b8b59 by Jason Merrill Committed by Jason Merrill

re PR c++/54021 ([c++0x] __builtin_constant_p should be constexpr)

	PR c++/54021
	* call.c (build_cxx_call): Set optimize when folding
	__builtin_constant_p in a constexpr function.

From-SVN: r189677
parent e1310984
2012-07-19 Jason Merrill <jason@redhat.com>
PR c++/54021
* call.c (build_cxx_call): Set optimize when folding
__builtin_constant_p in a constexpr function.
2012-07-18 Jason Merrill <jason@redhat.com>
* pt.c (instantiate_decl): Don't recheck substitutions.
......
......@@ -6900,6 +6900,7 @@ tree
build_cxx_call (tree fn, int nargs, tree *argarray)
{
tree fndecl;
int optimize_sav;
/* Remember roughly where this call is. */
location_t loc = EXPR_LOC_OR_HERE (fn);
......@@ -6916,8 +6917,15 @@ build_cxx_call (tree fn, int nargs, tree *argarray)
return error_mark_node;
/* Some built-in function calls will be evaluated at compile-time in
fold (). */
fold (). Set optimize to 1 when folding __builtin_constant_p inside
a constexpr function so that fold_builtin_1 doesn't fold it to 0. */
optimize_sav = optimize;
if (!optimize && fndecl && DECL_IS_BUILTIN_CONSTANT_P (fndecl)
&& current_function_decl
&& DECL_DECLARED_CONSTEXPR_P (current_function_decl))
optimize = 1;
fn = fold_if_not_in_template (fn);
optimize = optimize_sav;
if (VOID_TYPE_P (TREE_TYPE (fn)))
return fn;
......
2012-07-19 Jason Merrill <jason@redhat.com>
PR c++/54021
* g++.dg/cpp0x/constexpr-builtin2.C: New.
2012-07-19 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/discr38.adb: New test.
......
// PR c++/54021
// { dg-do compile { target c++11 } }
extern int nonconst_func(int);
constexpr int identity(int x) { return x; }
constexpr int zero() { return identity(0); }
constexpr int one() { return identity(1); }
// These are the same. Only the latter is accepted, though.
constexpr int rejected_const_4(int x)
{ return __builtin_constant_p(x) ? 4 : nonconst_func(x); }
constexpr int accepted_const_4(int x)
{ return identity(__builtin_constant_p(x)) ? 4 : nonconst_func(x); }
// This is rejected. I would like it to work.
constexpr int four = accepted_const_4(1);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment