I discovered very strange code in inject_parm_decls: if (args && is_this_parameter (args)) { gcc_checking_assert (current_class_ptr == NULL_TREE); current_class_ptr = NULL_TREE;
We are tripping up on the assert because when we call inject_parm_decls, current_class_ptr is set to 'A'. It was set by inject_this_parameter after we've parsed the parameter-declaration-clause of the member function foo. It seems correct to set ccp/ccr to A::B when we're late parsing the noexcept-specifiers of bar* functions in B, so that this-> does the right thing. Since inject_parm_decls can mess with ccp/ccr, I think best if we properly restore it after the late parsing of noexcept-specifiers. It should also work to clear ccp before calling inject_parm_decls, and removing the assignment following the assert, should the assert stay. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? gcc/cp/ChangeLog: PR c++/96623 * parser.c (inject_parm_decls): Remove a gcc_checking_assert. (cp_parser_class_specifier_1): Restore current_class_{ptr,ref} after late parsing of noexcept-specifiers. gcc/testsuite/ChangeLog: PR c++/96623 * g++.dg/cpp0x/noexcept64.C: New test. --- gcc/cp/parser.c | 8 ++++---- gcc/testsuite/g++.dg/cpp0x/noexcept64.C | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept64.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 4b2bca3fd11..8e86e92e273 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -24709,7 +24709,6 @@ inject_parm_decls (tree decl) if (args && is_this_parameter (args)) { - gcc_checking_assert (current_class_ptr == NULL_TREE); current_class_ptr = NULL_TREE; current_class_ref = cp_build_fold_indirect_ref (args); current_class_ptr = args; @@ -24967,7 +24966,6 @@ cp_parser_class_specifier_1 (cp_parser* parser) tree pushed_scope = NULL_TREE; unsigned ix; cp_default_arg_entry *e; - tree save_ccp, save_ccr; if (!type_definition_ok_p || any_erroneous_template_args_p (type)) { @@ -25012,6 +25010,8 @@ cp_parser_class_specifier_1 (cp_parser* parser) /* If there are noexcept-specifiers that have not yet been processed, take care of them now. Do this before processing NSDMIs as they may depend on noexcept-specifiers already having been processed. */ + tree save_ccp = current_class_ptr; + tree save_ccr = current_class_ref; FOR_EACH_VEC_SAFE_ELT (unparsed_noexcepts, ix, decl) { tree ctx = DECL_CONTEXT (decl); @@ -25063,10 +25063,10 @@ cp_parser_class_specifier_1 (cp_parser* parser) maybe_end_member_template_processing (); } vec_safe_truncate (unparsed_noexcepts, 0); + current_class_ptr = save_ccp; + current_class_ref = save_ccr; /* Now parse any NSDMIs. */ - save_ccp = current_class_ptr; - save_ccr = current_class_ref; FOR_EACH_VEC_SAFE_ELT (unparsed_nsdmis, ix, decl) { if (class_type != DECL_CONTEXT (decl)) diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept64.C b/gcc/testsuite/g++.dg/cpp0x/noexcept64.C new file mode 100644 index 00000000000..8b7303cd8a1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept64.C @@ -0,0 +1,24 @@ +// PR c++/96623 +// { dg-do compile { target c++11 } } + +constexpr int x = 0; +struct A { + int a1; + void foo (int p) { + int foovar; + struct B { + int b1; + void bar1 () noexcept(x); + void bar2 () noexcept(noexcept(this->b1)); + void bar3 () noexcept(noexcept(this->b2)); + void bar4 () noexcept(noexcept(a1)); + void bar5 () noexcept(noexcept(a2)); + void bar6 () noexcept(noexcept(b1)); + void bar7 () noexcept(noexcept(b2)); + void bar8 () noexcept(noexcept(foovar)); + void bar9 () noexcept(noexcept(p)); + int b2; + }; + } + int a2; +}; base-commit: f645da0e4ab9438dfd0c047c710c7ec6a7d6d8f3 -- 2.29.2