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 to lookup_template_variable


We need to use unknown_type_node for non-dependent arguments, too; we don't know what type the variable has until we look up the specialization.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit c348ed4ea7152054ff623a3efbca7fab49227a5f
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Nov 24 19:14:04 2014 -0500

    	* pt.c (lookup_template_variable): Always unknown_type_node.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 1d6b916..29fb2e1 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -8026,19 +8026,14 @@ lookup_template_class (tree d1, tree arglist, tree in_decl, tree context,
   return ret;
 }
 
-/* Return a TEMPLATE_ID_EXPR for the given variable template and ARGLIST. 
-   If the ARGLIST refers to any template parameters, the type of the
-   expression is the unknown_type_node since the template-id could
-   refer to an explicit or partial specialization. */
+/* Return a TEMPLATE_ID_EXPR for the given variable template and ARGLIST.
+   The type of the expression is the unknown_type_node since the
+   template-id could refer to an explicit or partial specialization. */
 
 tree
 lookup_template_variable (tree templ, tree arglist)
 {
-  tree type;
-  if (uses_template_parms (arglist))
-    type = unknown_type_node;
-  else
-    type = TREE_TYPE (templ);
+  tree type = unknown_type_node;
   tsubst_flags_t complain = tf_warning_or_error;
   tree parms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (templ));
   arglist = coerce_template_parms (parms, arglist, templ, complain,
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ17.C b/gcc/testsuite/g++.dg/cpp1y/var-templ17.C
new file mode 100644
index 0000000..c6d97eb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/var-templ17.C
@@ -0,0 +1,9 @@
+// DR 1727: a specialization doesn't need to have the same type
+// { dg-do compile { target c++14 } }
+
+template <class T> T t = 42;
+template<> void* t<int> = 0;
+
+template<class T, class U> struct same;
+template<class T> struct same<T,T> {};
+same<void*,decltype(t<int>)> s;

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