diff mbox

C++ PATCH for c++/56684 (ICE with const local in template)

Message ID 514CBD43.6090707@redhat.com
State New
Headers show

Commit Message

Jason Merrill March 22, 2013, 8:21 p.m. UTC
We were treating a constant VAR_DECL as non-dependent because it has a 
non-dependent type, even though it has a value-dependent initializer.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit d3a8f99d0ae9caf8d344b44a8e66632181a20157
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Mar 22 12:27:01 2013 -0400

    	PR c++/56684
    	* pt.c (instantiation_dependent_r): Check DECL_INITIAL of VAR_DECL
    	and CONST_DECL.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index b44c632..b6066c1 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -19942,6 +19942,13 @@  instantiation_dependent_r (tree *tp, int *walk_subtrees,
     case TREE_VEC:
       return NULL_TREE;
 
+    case VAR_DECL:
+    case CONST_DECL:
+      /* A constant with a dependent initializer is dependent.  */
+      if (value_dependent_expression_p (*tp))
+	return *tp;
+      break;
+
     case TEMPLATE_PARM_INDEX:
       return *tp;
 
diff --git a/gcc/testsuite/g++.dg/template/const6.C b/gcc/testsuite/g++.dg/template/const6.C
new file mode 100644
index 0000000..3c40d26
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/const6.C
@@ -0,0 +1,7 @@ 
+// PR c++/56684
+
+template < int T > struct S
+{
+  static const int Ti = T;
+  S() { 1 << Ti; }
+};