[gcc(refs/vendors/redhat/heads/gcc-8-branch)] c++: Local class DMI using local static [PR90749]
Jakub Jelinek
jakub@gcc.gnu.org
Thu Sep 17 17:03:56 GMT 2020
https://gcc.gnu.org/g:337eb489ce9deb565b808b51ee2e75cd12e95102
commit 337eb489ce9deb565b808b51ee2e75cd12e95102
Author: Jason Merrill <jason@redhat.com>
Date: Mon May 25 18:38:09 2020 -0400
c++: Local class DMI using local static [PR90749]
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++/90749
* init.c (get_nsdmi): Don't push_to_top_level for a local class.
Diff:
---
gcc/cp/init.c | 8 +++++---
gcc/testsuite/g++.dg/cpp0x/nsdmi-template20.C | 13 +++++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 1a2a1f58819..7bd3f0e548b 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -587,16 +587,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
index 00000000000..06448d92f12
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template20.C
@@ -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> ();
+}
More information about the Gcc-cvs
mailing list