Commit fa837fb6 by Jason Merrill Committed by Jason Merrill

re PR c++/65985 (compiler segfault with assert() in constexpr constructor body)

	PR c++/65985
	* constexpr.c (build_constexpr_constructor_member_initializers):
	Handle an additional STATEMENT_LIST.

From-SVN: r233514
parent bcb5f3c9
2016-02-17 Jason Merrill <jason@redhat.com> 2016-02-17 Jason Merrill <jason@redhat.com>
PR c++/65985
* constexpr.c (build_constexpr_constructor_member_initializers):
Handle an additional STATEMENT_LIST.
PR c++/68585 PR c++/68585
* constexpr.c (cxx_eval_bare_aggregate): Fix 'changed' detection. * constexpr.c (cxx_eval_bare_aggregate): Fix 'changed' detection.
......
...@@ -528,21 +528,32 @@ build_constexpr_constructor_member_initializers (tree type, tree body) ...@@ -528,21 +528,32 @@ build_constexpr_constructor_member_initializers (tree type, tree body)
{ {
vec<constructor_elt, va_gc> *vec = NULL; vec<constructor_elt, va_gc> *vec = NULL;
bool ok = true; bool ok = true;
if (TREE_CODE (body) == MUST_NOT_THROW_EXPR while (true)
|| TREE_CODE (body) == EH_SPEC_BLOCK) switch (TREE_CODE (body))
body = TREE_OPERAND (body, 0); {
if (TREE_CODE (body) == STATEMENT_LIST) case MUST_NOT_THROW_EXPR:
{ case EH_SPEC_BLOCK:
for (tree_stmt_iterator i = tsi_start (body); body = TREE_OPERAND (body, 0);
!tsi_end_p (i); tsi_next (&i)) break;
{
body = tsi_stmt (i); case STATEMENT_LIST:
if (TREE_CODE (body) == BIND_EXPR) for (tree_stmt_iterator i = tsi_start (body);
break; !tsi_end_p (i); tsi_next (&i))
} {
body = tsi_stmt (i);
if (TREE_CODE (body) == BIND_EXPR)
break;
}
break;
case BIND_EXPR:
body = BIND_EXPR_BODY (body);
goto found;
default:
gcc_unreachable ();
} }
if (TREE_CODE (body) == BIND_EXPR) found:
body = BIND_EXPR_BODY (body);
if (TREE_CODE (body) == CLEANUP_POINT_EXPR) if (TREE_CODE (body) == CLEANUP_POINT_EXPR)
{ {
body = TREE_OPERAND (body, 0); body = TREE_OPERAND (body, 0);
......
// PR c++/65985
// { dg-do compile { target c++14 } }
#include <cassert>
class Angle
{
int degrees = 0;
constexpr auto invariant() const noexcept
{
return 0 <= degrees && degrees < 360;
}
public:
explicit constexpr Angle(int n) noexcept
: degrees{n % 360}
{
assert(invariant());
}
/* implicit */ constexpr operator auto() const noexcept
{
return degrees;
}
};
int main()
{
static_assert(Angle{360} == 0, "");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment