diff options
author | Jason Merrill <jason@redhat.com> | 2020-05-01 13:53:32 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2020-05-01 13:53:34 -0400 |
commit | 82d5decef38b5562d97c49a70ca2636a08769dbc (patch) | |
tree | f6657a5d9b232db5e40d3cadf203972e495f6914 /gcc | |
parent | a2f32550a085984fbaaec962bf7723514ac71dff (diff) | |
download | gcc-82d5decef38b5562d97c49a70ca2636a08769dbc.zip gcc-82d5decef38b5562d97c49a70ca2636a08769dbc.tar.gz gcc-82d5decef38b5562d97c49a70ca2636a08769dbc.tar.bz2 |
c++: Local class DMI using local static [PR90479]
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/init.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/nsdmi-template20.C | 13 |
3 files changed, 23 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4468690..0675f98 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 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. + +2020-05-01 Jason Merrill <jason@redhat.com> + PR c++/91529 * decl.c (cp_finish_decl): Also clear TREE_READONLY if -fmerge-all-constants. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index ea95a3b..c7ae940 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -585,16 +585,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 0000000..06448d9 --- /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> (); +} |