This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.
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>();
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]