diff mbox

C++ PATCH for c++/48265 (ICE with variable used in its own initializer)

Message ID 4D9292D3.9020308@redhat.com
State New
Headers show

Commit Message

Jason Merrill March 30, 2011, 2:17 a.m. UTC
We were infinitely recursing in value_dependent_expression_p.  As it 
happens, we're already doing the heavy lifting for determining whether 
or not a potentially constant variable has a constant initializer, so we 
can just use decl_constant_var_p here.

Tested x86_64-pc-linux-gnu, applied to trunk and 4.6.
commit 5f044d8e087ad43de99c062fea1ed58398f6f977
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Mar 29 15:05:27 2011 -0400

    	PR c++/48265
    	* pt.c (value_dependent_expression_p) [VAR_DECL]: Make sure
    	the variable is constant before looking at its initializer.
diff mbox

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index da9365f..e716ca6 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -18085,10 +18085,10 @@  value_dependent_expression_p (tree expression)
       return value_dependent_expression_p (DECL_INITIAL (expression));
 
     case VAR_DECL:
-       /* A constant with integral or enumeration type and is initialized
+       /* A constant with literal type and is initialized
 	  with an expression that is value-dependent.  */
       if (DECL_INITIAL (expression)
-	  && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (expression))
+	  && decl_constant_var_p (expression)
 	  && value_dependent_expression_p (DECL_INITIAL (expression)))
 	return true;
       return false;
diff --git a/gcc/testsuite/g++.dg/cpp0x/regress/value-dep1.C b/gcc/testsuite/g++.dg/cpp0x/regress/value-dep1.C
new file mode 100644
index 0000000..112389d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/regress/value-dep1.C
@@ -0,0 +1,7 @@ 
+// PR c++/48265
+// { dg-options -std=c++0x }
+
+template < int > struct S
+{
+  S () { const int i = i; i; };
+};