Patchwork C++ PATCH for c++/53836 (dependent parenthesized initializer)

login
register
mail settings
Submitter Jason Merrill
Date Sept. 13, 2012, 2:47 p.m.
Message ID <5051F206.1080502@redhat.com>
Download mbox | patch
Permalink /patch/183638/
State New
Headers show

Comments

Jason Merrill - Sept. 13, 2012, 2:47 p.m.
When a parenthesized initializer has dependent elements, we leave it as 
a TREE_LIST.  We shouldn't let that confuse us into thinking that it 
isn't value-dependent.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.

Patch

commit 26bd4898faf6a74d3e5f1531790cabd1a5d25d8a
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Sep 11 21:49:30 2012 -0400

    	PR c++/53836
    	* pt.c (value_dependent_expression_p): A TREE_LIST initializer must
    	be dependent.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 768f141..4cf2ed8 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -19199,10 +19199,15 @@  value_dependent_expression_p (tree expression)
 
     case VAR_DECL:
        /* A constant with literal type and is initialized
-	  with an expression that is value-dependent.  */
+	  with an expression that is value-dependent.
+
+          Note that a non-dependent parenthesized initializer will have
+          already been replaced with its constant value, so if we see
+          a TREE_LIST it must be dependent.  */
       if (DECL_INITIAL (expression)
 	  && decl_constant_var_p (expression)
-	  && value_dependent_expression_p (DECL_INITIAL (expression)))
+	  && (TREE_CODE (DECL_INITIAL (expression)) == TREE_LIST
+	      || value_dependent_expression_p (DECL_INITIAL (expression))))
 	return true;
       return false;
 
diff --git a/gcc/testsuite/g++.dg/template/init10.C b/gcc/testsuite/g++.dg/template/init10.C
new file mode 100644
index 0000000..1480622
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/init10.C
@@ -0,0 +1,15 @@ 
+template <int N>
+struct A { };
+
+template <int Q>
+void g()
+{
+    const int M ( Q );
+
+    A<M> a;
+}
+
+void h()
+{
+    g<3>();
+}