diff mbox

C++ PATCH for c++/68449 (segv with compound statement)

Message ID 20160108174856.GL31604@redhat.com
State New
Headers show

Commit Message

Marek Polacek Jan. 8, 2016, 5:48 p.m. UTC
An attempt to fix c++/68449.  We ICEd because pointer returned from
ctx->values->get points to NULL, so checking DECL_P on that is no no.
Fixed along the lines Jakub suggested in the PR.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2016-01-08  Marek Polacek  <polacek@redhat.com>

	PR c++/68449
	* constexpr.c (cxx_eval_constant_expression): Handle NULL initializer.

	* g++.dg/pr68449.C: New.


	Marek

Comments

Jason Merrill Jan. 8, 2016, 5:56 p.m. UTC | #1
On 01/08/2016 12:48 PM, Marek Polacek wrote:
>   	if (tree *p = ctx->values->get (r))
>   	  r = *p;
> -      if (DECL_P (r))
> +      if (r == NULL_TREE || DECL_P (r))

I think it would be a bit better not to change r if *p is null.  OK with 
that change.

Jason
diff mbox

Patch

diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c
index bcf26a6..f59d010 100644
--- gcc/cp/constexpr.c
+++ gcc/cp/constexpr.c
@@ -3195,7 +3195,7 @@  cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
       if (VAR_P (r))
 	if (tree *p = ctx->values->get (r))
 	  r = *p;
-      if (DECL_P (r))
+      if (r == NULL_TREE || DECL_P (r))
 	{
 	  if (!ctx->quiet)
 	    non_const_var_error (r);
diff --git gcc/testsuite/g++.dg/pr68449.C gcc/testsuite/g++.dg/pr68449.C
index e69de29..7d86fe9 100644
--- gcc/testsuite/g++.dg/pr68449.C
+++ gcc/testsuite/g++.dg/pr68449.C
@@ -0,0 +1,9 @@ 
+// PR c++/68449
+// { dg-do compile }
+// { dg-options "-Wsign-compare" }
+
+int
+foo (int a)
+{
+  return __extension__ ({ int b; b; }) < 0;
+}