This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ PATCH] Fix __builtin_{is_constant_evaluated,constant_p} handling in static_assert (PR c++/86524, PR c++/88446)

On 12/20/18 4:08 PM, Jakub Jelinek wrote:
On Thu, Dec 20, 2018 at 02:47:01PM -0500, Jason Merrill wrote:
--- gcc/cp/constexpr.c.jj	2018-12-12 09:34:17.531736075 +0100
+++ gcc/cp/constexpr.c	2018-12-12 11:30:33.986756914 +0100
@@ -1198,6 +1198,7 @@ cxx_eval_builtin_function_call (const co
        in a constexpr function until we have values for the parameters.  */
     if (bi_const_p
         && ctx->quiet
+      && !ctx->manifestly_const_eval

I think we want to replace the "quiet" check with manifestly_const_eval,
rather than adding to it.

Will change that.

-	args[i] = cxx_eval_constant_expression (&new_ctx, args[i], false,
-						&dummy1, &dummy2);
+	{
+	  bool non_cst_p = false, ovf_p = false;
+	  tree a = cxx_eval_constant_expression (&new_ctx, args[i], false,
+						 &non_cst_p, &ovf_p);
+	  if ((non_cst_p || ovf_p) && ctx->manifestly_const_eval)
+	    {
+	      new_ctx.manifestly_const_eval = false;
+	      non_cst_p = false;
+	      ovf_p = false;
+	      a = cxx_eval_constant_expression (&new_ctx, args[i], false,
+						&non_cst_p, &ovf_p);
+	      new_ctx.manifestly_const_eval = true;
+	    }

Why retry without manifestly_const_eval?  For static initialization we don't
want to try constant evaluation again with __builtin_is_constant_evaluated
false if it failed with it true.

The point is that we don't actually require arguments of the builtins to be
constant expressions.

Right, but they either are or they aren't. Doing this isn't likely to help anything, and can lead to paradoxical results in contrived testcases.

But if you think this is a bad idea, I can remove it, I haven't been
successful in constructing a testcase where this would matter.

Please.  OK with those changes.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]