Commit 61b6d4cd by Dodji Seketeli Committed by Dodji Seketeli

Avoid crashing on erroneous static_assert usage

When working on something else, I noticed that failing to provide the
second argument to the static_assert operator would lead to an ICE.

Fixed thus, and tested against trunk on x86_64-unknown-linux-gnu.

gcc/cp/

	* semantics.c (finish_static_assert): Don't crash on erroneous
	message or condition.

gcc/testsuite/

	* g++.dg/cpp0x/static_assert8.C: New test.

From-SVN: r190182
parent a4a83796
2012-08-06 Dodji Seketeli <dodji@redhat.com>
Avoid crashing on erroneous static_assert usage
* semantics.c (finish_static_assert): Don't crash on erroneous
message or condition.
2012-08-06 Marc Glisse <marc.glisse@inria.fr> 2012-08-06 Marc Glisse <marc.glisse@inria.fr>
Paolo Carlini <paolo.carlini@oracle.com> Paolo Carlini <paolo.carlini@oracle.com>
......
...@@ -5099,6 +5099,12 @@ void ...@@ -5099,6 +5099,12 @@ void
finish_static_assert (tree condition, tree message, location_t location, finish_static_assert (tree condition, tree message, location_t location,
bool member_p) bool member_p)
{ {
if (message == NULL_TREE
|| message == error_mark_node
|| condition == NULL_TREE
|| condition == error_mark_node)
return;
if (check_for_bare_parameter_packs (condition)) if (check_for_bare_parameter_packs (condition))
condition = error_mark_node; condition = error_mark_node;
......
2012-08-06 Dodji Seketeli <dodji@redhat.com>
Avoid crashing on erroneous static_assert usage
* g++.dg/cpp0x/static_assert8.C: New test.
2012-08-06 Jason Merrill <jason@redhat.com> 2012-08-06 Jason Merrill <jason@redhat.com>
* g++.dg/cpp0x/sfinae38.C: New. * g++.dg/cpp0x/sfinae38.C: New.
......
// { dg-do compile { target c++11 } }
static_assert (1 == 0); // { dg-error "expected (string-literal|',') before" }
static_assert (1 == 0,); // { dg-error "expected string-literal before '\\)'" }
static_assert (1 == 0, "oops"); // { dg-error "static assertion failed" }
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