PR c++/85113 - ICE with constexpr and __builtin_constant_p.
authorJason Merrill <jason@redhat.com>
Tue, 3 Apr 2018 19:13:36 +0000 (15:13 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 3 Apr 2018 19:13:36 +0000 (15:13 -0400)
* constexpr.c (cxx_eval_builtin_function_call): Only defer
__builtin_constant_p if ctx->quiet.

From-SVN: r259051

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/ext/builtin12.C [new file with mode: 0644]

index 505b2257be294d1c87041081cdda3df25c2511c1..648a71d4897f142553c6fe64a3eda28a6103fb72 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-03  Jason Merrill  <jason@redhat.com>
+
+       PR c++/85113 - ICE with constexpr and __builtin_constant_p.
+       * constexpr.c (cxx_eval_builtin_function_call): Only defer
+       __builtin_constant_p if ctx->quiet.
+
 2018-04-03  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/84768
index bebd9f5b5d0b9d43ea96037fa4a4858fe3ef720c..201f27d8e6649397984c748a899c16673476a6d5 100644 (file)
@@ -1171,7 +1171,10 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun,
   /* Don't fold __builtin_constant_p within a constexpr function.  */
   bool bi_const_p = (DECL_FUNCTION_CODE (fun) == BUILT_IN_CONSTANT_P);
 
+  /* If we aren't requiring a constant expression, defer __builtin_constant_p
+     in a constexpr function until we have values for the parameters.  */
   if (bi_const_p
+      && ctx->quiet
       && current_function_decl
       && DECL_DECLARED_CONSTEXPR_P (current_function_decl))
     {
diff --git a/gcc/testsuite/g++.dg/ext/builtin12.C b/gcc/testsuite/g++.dg/ext/builtin12.C
new file mode 100644 (file)
index 0000000..1d6bb75
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/85113
+// { dg-do compile { target c++14 } }
+
+template<bool> struct A {};
+
+constexpr int foo()
+{
+  A<__builtin_constant_p(0)> a{};
+  return 0;
+}