c++: ICE on invalid with inheriting constructors [PR94751]
commitd4e0bdbc036644401f9de49f594b2bb16b287381
authorMarek Polacek <polacek@redhat.com>
Fri, 5 Mar 2021 20:46:50 +0000 (5 15:46 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 25 Mar 2021 20:11:29 +0000 (25 16:11 -0400)
tree9aff239d30e7a17d1fffca0c5fb9fd2e692607cd
parent0b86a6438191f720bebf880a2b932cd97d10229a
c++: ICE on invalid with inheriting constructors [PR94751]

This is an ICE on invalid where we crash because since r269032 we
keep error_mark_node around instead of using noexcept_false_spec
when things go wrong; see the walk_field_subobs hunk.

We crash in deduce_inheriting_ctor which calls synthesized_method_walk
to deduce the exception-specification, but fails to do so in this case,
because the testcase is invalid so get_nsdmi returns error_mark_node for
the member 'c', and per r269032 the error_mark_node propagates back to
deduce_inheriting_ctor which subsequently calls build_exception_variant
whereon we crash.  I think we should return early if the deduction fails
and I decided to call mark_used to get an error right away instead of
hoping that it would get called later.  My worry is that we could forget
that there was an error and think that we just deduced noexcept(false).

And then I noticed that the test still crashes in C++98.  Here again we
failed to deduce the exception-specification in implicitly_declare_fn,
but nothing reported an error between synthesized_method_walk and the
assert.  Well, not much we can do except calling synthesized_method_walk
again, this time in the verbose mode and making sure that we did get an
error.

gcc/cp/ChangeLog:

PR c++/94751
* call.c (build_over_call): Maybe call mark_used in case
deduce_inheriting_ctor fails and return error_mark_node.
* cp-tree.h (deduce_inheriting_ctor): Adjust declaration.
* method.c (deduce_inheriting_ctor): Return bool if the deduction
fails.
(implicitly_declare_fn): If raises is error_mark_node, call
synthesized_method_walk with diag being true.

gcc/testsuite/ChangeLog:

PR c++/94751
* g++.dg/cpp0x/inh-ctor37.C: New test.
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/method.c
gcc/testsuite/g++.dg/cpp0x/inh-ctor37.C [new file with mode: 0644]