Fix PR c++/70332 (ICE due to aggregate initialization of NSDMI)
authorPatrick Palka <ppalka@gcc.gnu.org>
Wed, 23 Mar 2016 21:02:34 +0000 (21:02 +0000)
committerPatrick Palka <ppalka@gcc.gnu.org>
Wed, 23 Mar 2016 21:02:34 +0000 (21:02 +0000)
gcc/cp/ChangeLog:

PR c++/70332
* pt.c (tsubst_copy) [PARM_DECL]: Handle the use of 'this' in an
NSDMI that's part of an aggregrate initialization.

gcc/testsuite/ChangeLog:

PR c++/70332
* g++.dg/cpp1y/nsdmi-aggr5.C: New test.

From-SVN: r234442

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr5.C [new file with mode: 0644]

index 42c7054637838edeea144012e17c69302900ab6d..984a030286b754f5306db3375b92cf9d2ce3d932 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-23  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/70332
+       * pt.c (tsubst_copy) [PARM_DECL]: Handle the use of 'this' in an
+       NSDMI that's part of an aggregrate initialization.
+
 2016-03-23  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/70001
index 68374389f3beb184932edd4c1de2ddfbd09aa79f..a6398c04f85e0cdf9e187be6554276402d222c2e 100644 (file)
@@ -13878,10 +13878,13 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 
       if (r == NULL_TREE)
        {
-         /* We get here for a use of 'this' in an NSDMI.  */
+         /* We get here for a use of 'this' in an NSDMI as part of a
+            constructor call or as part of an aggregate initialization.  */
          if (DECL_NAME (t) == this_identifier
-             && current_function_decl
-             && DECL_CONSTRUCTOR_P (current_function_decl))
+             && ((current_function_decl
+                  && DECL_CONSTRUCTOR_P (current_function_decl))
+                 || (current_class_ref
+                     && TREE_CODE (current_class_ref) == PLACEHOLDER_EXPR)))
            return current_class_ptr;
 
          /* This can happen for a parameter name used later in a function
index 1b3283286c37627efcf922560c2cbf59fa93c443..5e3227643855dd00a39625a78c90bfea9ffc24dc 100644 (file)
@@ -1,3 +1,8 @@
+2016-03-23  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/70332
+       * g++.dg/cpp1y/nsdmi-aggr5.C: New test.
+
 2016-03-23  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/70001
diff --git a/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr5.C b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr5.C
new file mode 100644 (file)
index 0000000..fe377c3
--- /dev/null
@@ -0,0 +1,24 @@
+// PR c++/70332
+// { dg-do run { target c++14 } }
+
+template <class T>
+struct C
+{
+ T m;
+ T *n = &m;
+};
+
+C<int> c { };
+
+int
+main ()
+{
+  *c.n = 5;
+  if (c.m != 5)
+    __builtin_abort ();
+
+  C<int> d { 10 };
+  *d.n = *d.n + 1;
+  if (d.m != 11)
+    __builtin_abort ();
+}