From 61b6d4cdee65148788a7638495ae61f8f2c93272 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Mon, 6 Aug 2012 16:19:09 +0000 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/semantics.c | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/static_assert8.C | 7 +++++++ 4 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/static_assert8.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 86c9097f67fe..5452a1cb836b 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 b27e8ab128b7..230e967ca93a 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 b362c79dfb51..cca64c46ca84 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 000000000000..ea23afb857df --- /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" }