Avoid crashing on erroneous static_assert usage
authorDodji Seketeli <dodji@redhat.com>
Mon, 6 Aug 2012 16:19:09 +0000 (16:19 +0000)
committerDodji Seketeli <dodji@gcc.gnu.org>
Mon, 6 Aug 2012 16:19:09 +0000 (18:19 +0200)
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
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/static_assert8.C [new file with mode: 0644]

index 86c9097f67fe00a86671bdb6789eff24fb9e87c9..5452a1cb836ba967e270b655a04047b9cde6b934 100644 (file)
@@ -1,3 +1,9 @@
+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>
            Paolo Carlini  <paolo.carlini@oracle.com>
 
index b27e8ab128b74e49a8040c632d9a6e9f798d0fb6..230e967ca93a7d28986b39756d2d96365826939e 100644 (file)
@@ -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;
 
index b362c79dfb5149caacccf1857d49e72697f15d38..cca64c46ca84ce4b97f2854637c8362790a4cf92 100644 (file)
@@ -1,3 +1,8 @@
+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>
 
        * 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 (file)
index 0000000..ea23afb
--- /dev/null
@@ -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" }