public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/80562, ICE with C++17 constexpr if
@ 2017-06-19 20:50 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2017-06-19 20:50 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 142 bytes --]

We need to call instantiate_non_dependent_expr before
cxx_constant_value in a template.

Tested x86_64-pc-linux-gnu, applying to trunk and 7.

[-- Attachment #2: 80562.diff --]
[-- Type: text/plain, Size: 1387 bytes --]

commit 1645e51aeab6cea4e7206cb6a3520eaf383e47f6
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jun 19 15:47:47 2017 -0400

            PR c++/80562 - ICE with constexpr if.
    
            * semantics.c (finish_if_stmt_cond): Call
            instantiate_non_dependent_expr.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 5b5ec54..5fe772a 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -733,7 +733,10 @@ finish_if_stmt_cond (tree cond, tree if_stmt)
   if (IF_STMT_CONSTEXPR_P (if_stmt)
       && require_potential_rvalue_constant_expression (cond)
       && !value_dependent_expression_p (cond))
-    cond = cxx_constant_value (cond, NULL_TREE);
+    {
+      cond = instantiate_non_dependent_expr (cond);
+      cond = cxx_constant_value (cond, NULL_TREE);
+    }
   finish_cond (&IF_COND (if_stmt), cond);
   add_stmt (if_stmt);
   THEN_CLAUSE (if_stmt) = push_stmt_list ();
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if12.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if12.C
new file mode 100644
index 0000000..1ed2c30
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if12.C
@@ -0,0 +1,14 @@
+// PR c++/80562
+// { dg-options -std=c++1z }
+
+struct T {
+  constexpr auto foo() { return false; }
+};
+
+template <class MustBeTemplate>
+constexpr auto bf(T t) {
+    if constexpr(t.foo()) {
+        return false;
+    }
+    return true;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-06-19 20:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-19 20:50 C++ PATCH for c++/80562, ICE with C++17 constexpr if Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).