]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Local class DMI using local static [PR90479]
authorJason Merrill <jason@redhat.com>
Mon, 25 May 2020 22:38:09 +0000 (18:38 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 25 May 2020 22:38:10 +0000 (18:38 -0400)
For default member initializers in templates it's important to push into the
right context during get_nsdmi.  But for a local class that's not possible,
and trying leaves the function context we need to be in, so don't try.

gcc/cp/ChangeLog
2020-05-01  Jason Merrill  <jason@redhat.com>

PR c++/90479
* init.c (get_nsdmi): Don't push_to_top_level for a local class.

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/g++.dg/cpp0x/nsdmi-template20.C [new file with mode: 0644]

index 899f47ae7cbddd122f97f7bd5a92b2de64a140da..7626511b9ca2c247094355214c2c926098a1ca9c 100644 (file)
@@ -1,3 +1,8 @@
+2020-05-25  Jason Merrill  <jason@redhat.com>
+
+       PR c++/90479
+       * init.c (get_nsdmi): Don't push_to_top_level for a local class.
+
 2020-05-25  Jason Merrill  <jason@redhat.com>
 
        PR c++/91529
index fcc91fc91727e9f8a2fc910b746d0900c2e6fe32..c5a01c83093a36da27191ca9e4073f843ce65f08 100644 (file)
@@ -586,16 +586,18 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain)
          DECL_INSTANTIATING_NSDMI_P (member) = 1;
 
          bool pushed = false;
-         if (!currently_open_class (DECL_CONTEXT (member)))
+         tree ctx = DECL_CONTEXT (member);
+         if (!currently_open_class (ctx)
+             && !LOCAL_CLASS_P (ctx))
            {
              push_to_top_level ();
-             push_nested_class (DECL_CONTEXT (member));
+             push_nested_class (ctx);
              pushed = true;
            }
 
          gcc_checking_assert (!processing_template_decl);
 
-         inject_this_parameter (DECL_CONTEXT (member), TYPE_UNQUALIFIED);
+         inject_this_parameter (ctx, TYPE_UNQUALIFIED);
 
          start_lambda_scope (member);
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template20.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template20.C
new file mode 100644 (file)
index 0000000..06448d9
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/90479
+// { dg-do compile { target c++11 } }
+
+template <int n>
+void foo ()
+{
+  static int i {100};
+  struct { int a {i++}; } b {};
+}
+int main ()
+{
+  foo<0> ();
+}