This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix PR c++/18962: use arg list from definition, not declaration
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: 22 Dec 2004 05:56:26 -0200
- Subject: Fix PR c++/18962: use arg list from definition, not declaration
- Organization: Red Hat Global Engineering Services Compiler Team
The testcase in the bug report follows:
template<class T1,int N1>
class Class
{
public:
template <class T2,int N2> void function( const Class<T2,N2>& );
};
template<>
template<class T2,int N2>
void Class<int,1>::function( const Class<T2,N2>& param )
{
param;// line 12
}
int main()
{
Class<int,1> instance;
Class<char,2> param;
instance.function( param );
}
It illustrates a problem in the current code: in a definition of a
template specialization, we disregard the (function, not template)
argument list given in the definition, and use the argument list from
the original declaration, because determine_specialization() builds a
new tmpl out of the original declarations, without paying attention to
the argument list in the decl built out of the declarator parsed for
the definition.
Taking the arg list from the decl fixes the problem the testcase
above, but I can't tell upfront whether this could have any ill
effects. Could someone more familiar with this code please review
this patch? I'm regression-testing it on x86_64-linux-gnu now, ok to
install along with the testcase if it passes?
Index: gcc/cp/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR c++/18962
* pt.c (check_explicit_specialization): Use the argument list from
the definition in a template function specialization definition.
Index: gcc/cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.959
diff -u -p -r1.959 pt.c
--- gcc/cp/pt.c 16 Dec 2004 11:03:32 -0000 1.959
+++ gcc/cp/pt.c 22 Dec 2004 07:40:57 -0000
@@ -2051,6 +2051,10 @@ check_explicit_specialization (tree decl
DECL_SOURCE_LOCATION (tmpl) = DECL_SOURCE_LOCATION (decl);
DECL_SOURCE_LOCATION (DECL_TEMPLATE_RESULT (tmpl))
= DECL_SOURCE_LOCATION (decl);
+ /* We want to use the argument list specified in the
+ definition, not in the original declaration. */
+ DECL_ARGUMENTS (DECL_TEMPLATE_RESULT (tmpl))
+ = DECL_ARGUMENTS (decl);
}
return tmpl;
}
--
Alexandre Oliva http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}