diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 86c9097f67f..5452a1cb836 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2012-08-06 Dodji Seketeli + + 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 Paolo Carlini diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index b27e8ab128b..230e967ca93 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -5099,6 +5099,12 @@ void finish_static_assert (tree condition, tree message, location_t location, 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)) condition = error_mark_node; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b362c79dfb5..cca64c46ca8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-08-06 Dodji Seketeli + + Avoid crashing on erroneous static_assert usage + * g++.dg/cpp0x/static_assert8.C: New test. + 2012-08-06 Jason Merrill * g++.dg/cpp0x/sfinae38.C: New. diff --git a/gcc/testsuite/g++.dg/cpp0x/static_assert8.C b/gcc/testsuite/g++.dg/cpp0x/static_assert8.C new file mode 100644 index 00000000000..ea23afb857d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/static_assert8.C @@ -0,0 +1,7 @@ +// { 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" }