PR c++/79461 - ICE with lambda in constexpr constructor
authorJason Merrill <jason@redhat.com>
Mon, 13 Feb 2017 22:31:12 +0000 (17:31 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 13 Feb 2017 22:31:12 +0000 (17:31 -0500)
* constexpr.c (build_data_member_initialization): Ignore
initialization of a local variable.

From-SVN: r245410

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

index 994492be7d946499b964c06a4ca583d84b7fc3af..3d840c5e12f086a944fbcd808e74d57a22c144c6 100644 (file)
@@ -1,3 +1,9 @@
+2017-02-13  Jason Merrill  <jason@redhat.com>
+
+       PR c++/79461 - ICE with lambda in constexpr constructor
+       * constexpr.c (build_data_member_initialization): Ignore
+       initialization of a local variable.
+
 2017-02-13  Jakub Jelinek  <jakub@redhat.com>
 
        * init.c (warn_placement_new_too_small): Add missing space in
index bfdde9e911dd28a246cd99130cc5cd7027288307..004bb45b87ed8b183e37ea41778d127192adac57 100644 (file)
@@ -379,6 +379,9 @@ build_data_member_initialization (tree t, vec<constructor_elt, va_gc> **vec)
   if (TREE_CODE (member) == COMPONENT_REF)
     {
       tree aggr = TREE_OPERAND (member, 0);
+      if (TREE_CODE (aggr) == VAR_DECL)
+       /* Initializing a local variable, don't add anything.  */
+       return true;
       if (TREE_CODE (aggr) != COMPONENT_REF)
        /* Normal member initialization.  */
        member = TREE_OPERAND (member, 1);
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda15.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda15.C
new file mode 100644 (file)
index 0000000..7e05481
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/79461
+// { dg-options -std=c++1z }
+
+struct S {
+  constexpr S(int i) {
+    auto f = [i]{};
+  }
+};
+int main() {}
+