Contract assert is an attribute on an empty statement. Currently we assert
that the statement is empty before emitting the assertion. This has been
changed to a conditional check that the statement is empty before the
assertion is emitted.
PR c++/117579
gcc/cp/ChangeLog:
* parser.cc (cp_parser_statement): Replace assertion with a
conditional check that the statement containing a contract assert
is empty.
gcc/testsuite/ChangeLog:
* g++.dg/contracts/pr117579.C: New test.
Signed-off-by: Nina Ranns <dinka.ranns@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
if (cp_contract_assertion_p (std_attrs))
{
/* Add the assertion as a statement in the current block. */
- gcc_assert (!statement || statement == error_mark_node);
- emit_assertion (std_attrs);
+ if (!statement)
+ emit_assertion (std_attrs);
+ /* We already checked that the contract assertion is followed by
+ a semicolon. */
std_attrs = NULL_TREE;
}
}
--- /dev/null
+// Check that contract assertion on a non-empty statement doesn't cause an
+// ICE.
+// { dg-options "-std=c++2a -fcontracts " }
+
+void f();
+int main ()
+{
+ [[assert: true]] f(); // { dg-error "assertions must be followed by" }
+}