re PR c++/33239 (internal compiler error in instantiate_class_template, at cp/pt...
authorJason Merrill <jason@redhat.com>
Mon, 24 Sep 2007 20:54:34 +0000 (16:54 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 24 Sep 2007 20:54:34 +0000 (16:54 -0400)
        PR c++/33239
        * pt.c (resolve_typename_type): Don't look things up in the original
        template if it would mean losing template arguments.

From-SVN: r128725

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/template/memtmpl3.C [new file with mode: 0644]

index 5e9b1875b2eb558e0b1596c853e3333c195d0f76..6950166f13a9b0c46a6c1d11b52cf44f0dff1c52 100644 (file)
@@ -1,3 +1,9 @@
+2007-09-24  Jason Merrill  <jason@redhat.com>
+
+       PR c++/33239
+       * pt.c (resolve_typename_type): Don't look things up in the original
+       template if it would mean losing template arguments.    
+
 2007-09-24  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/33506
index c9ec37034a58c1681c5c38e303b9ced0ebca3aa5..5b07c7027a7a1cee1dc9547433d60a10202b6df4 100644 (file)
@@ -15732,9 +15732,16 @@ resolve_typename_type (tree type, bool only_current_p)
      to look inside it.  */
   if (only_current_p && !currently_open_class (scope))
     return type;
-  /* If SCOPE is a partial instantiation, it will not have a valid
-     TYPE_FIELDS list, so use the original template.  */
-  scope = CLASSTYPE_PRIMARY_TEMPLATE_TYPE (scope);
+  /* If SCOPE isn't the template itself, it will not have a valid
+     TYPE_FIELDS list.  */
+  if (same_type_p (scope, CLASSTYPE_PRIMARY_TEMPLATE_TYPE (scope)))
+    /* scope is either the template itself or a compatible instantiation
+       like X<T>, so look up the name in the original template.  */
+    scope = CLASSTYPE_PRIMARY_TEMPLATE_TYPE (scope);
+  else
+    /* scope is a partial instantiation, so we can't do the lookup or we
+       will lose the template arguments.  */
+    return type;
   /* Enter the SCOPE so that name lookup will be resolved as if we
      were in the class definition.  In particular, SCOPE will no
      longer be considered a dependent type.  */
diff --git a/gcc/testsuite/g++.dg/template/memtmpl3.C b/gcc/testsuite/g++.dg/template/memtmpl3.C
new file mode 100644 (file)
index 0000000..583155e
--- /dev/null
@@ -0,0 +1,24 @@
+// PR c++/33239
+
+struct null_type;
+
+template<typename T1, typename T2>
+struct tuple_impl
+{
+  template<typename U>
+  struct append
+  {
+    typedef tuple_impl<U, null_type> type;
+  };
+
+  int data;
+};
+
+template<typename T1>
+class tuple
+: public tuple_impl<T1, null_type>::template append<T1>::type
+{
+  using tuple_impl<T1, null_type>::template append<T1>::type::data;
+};
+
+tuple<int>  my_tuple;