Patchwork C++ PATCH for c++/46304 (ICE with _Complex)

login
register
mail settings
Submitter Jason Merrill
Date April 20, 2011, 6:35 a.m.
Message ID <4DAE7E96.2000009@redhat.com>
Download mbox | patch
Permalink /patch/92091/
State New
Headers show

Comments

Jason Merrill - April 20, 2011, 6:35 a.m.
In this bug, the underlying problem was that we had a COMPLEX_EXPR 
representing a complex constant rather than a COMPLEX_CST.  There was 
also the issue that 4.5 didn't deal with this very well, but fixing the 
testcase to use COMPLEX_CST (by folding the COMPLEX_EXPR case like we do 
everything else in cp_build_binary_op) fixes the ICE.

Tested x86_64-pc-linux-gnu, applied to trunk, 4.5 and 4.6.
commit 58d863dc8ff1f357a7f8f4064c204779a2b2c2eb
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Apr 19 17:58:20 2011 -0700

    	PR c++/46304
    	* typeck.c (cp_build_binary_op): Fold COMPLEX_EXPR.

Patch

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 89d3247..dcdc790 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -4357,7 +4357,11 @@  cp_build_binary_op (location_t location,
 		  gcc_unreachable();
 		}
 	    }
-	  return build2 (COMPLEX_EXPR, result_type, real, imag);
+	  real = fold_if_not_in_template (real);
+	  imag = fold_if_not_in_template (imag);
+	  result = build2 (COMPLEX_EXPR, result_type, real, imag);
+	  result = fold_if_not_in_template (result);
+	  return result;
 	}
 
       /* For certain operations (which identify themselves by shorten != 0)
diff --git a/gcc/testsuite/g++.dg/ext/complex7.C b/gcc/testsuite/g++.dg/ext/complex7.C
new file mode 100644
index 0000000..9d5463f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/complex7.C
@@ -0,0 +1,6 @@ 
+// { dg-options "" }
+
+class A
+{
+  static const _Complex double x = 1.0 + 2.0i;
+};