Commit Message

Hello,
Consider this short code snippet:
struct A
{
~A();
};
struct B
{
A a;
constexpr B() {}
};
As explained in the audit trail, this is valid code.
G++ ICEs on it because build_constexpr_constructor_member_initializers
chokes on a CLEANUP_STMT.
The CLEANUP_STMT is put into the constructor of B to ensure that the
destructor for 'a' is called.
As this CLEANUP_STMT is not related to the representation of
mem-initializer-list that
build_constexpr_constructor_member_initializers was expecting to see
as part of its analysis of the constructor body my understanding is
that it should just ignore it.
I noted that build_data_member_initialization that is called elsewhere
in build_constexpr_constructor_member_initializers already knows how
to ignore those CLEANUP_STMT, so I tried in this patch to take
advantage of that function.
The other case of ICE reported in this issue is in:
struct A2
{
constexpr A2() {}
~A2();
};
struct B2
{
A2 a;
constexpr B2() { return;}
};
where check_constexpr_ctor_body fails to recognize that the body of
the constexpr constructor B2 is not empty. It turned out this is
because it's not passed the proper last statement of the constructor,
before the body (as written in the source code) is parsed. Fixed
thus.
Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk.
gcc/cp/
* semantics.c (cp_parser_ctor_initializer_opt_and_function_body):
Set the pointer to the last block of the constructor to the
current statement.
(build_constexpr_constructor_member_initializers): Get
build_data_member_initialization a chance to deal with more
statements before we choke.
gcc/testsuite/
* g++.dg/cpp0x/constexpr-diag4.C: New test.
---
gcc/cp/parser.c | 2 +-
gcc/cp/semantics.c | 2 +
gcc/testsuite/g++.dg/cpp0x/constexpr-diag4.C | 28 +++++++++++++++
gcc/testsuite/g++.dg/cpp0x/constexpr-diag5.C | 48 ++++++++++++++++++++++++++
4 files changed, 79 insertions(+), 1 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-diag4.C
create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-diag5.C