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] [PR14409] Check constness of member function during specialization (regression)


Hello,

determine_specialization has code to deals with specializations of member
templates. To check if a specialization matches a given function template
declaration, it mainly uses get_bindings to see if it can constuct a full
argument list. But this does not take into account the constness of the member
function. In fact, it turns out that it is possible to mismatch the constness
of a member template function in an explicit instantiation without GCC noticing
it (see the testcase).

This patch fixes it with an explicit check. Tested on i686-pc-linux-gnu with no
new regressions, OK for mainline, 3.4 and 3.3?

Giovanni Bajo


cp/
2004-03-04  Giovanni Bajo  <giovannibajo@gcc.gnu.org>

        PR c++/14409
        * pt.c (determine_specialization): For member templates, match also
        constness.

testsuite/
2004-03-04  Giovanni Bajo  <giovannibajo@gcc.gnu.org>

        PR c++/14409
        * g++.dg/template/spec12.C: New test.


Index: pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.830
diff -c -3 -p -r1.830 pt.c
*** pt.c 14 Feb 2004 11:28:59 -0000 1.830
--- pt.c 4 Mar 2004 02:28:38 -0000
*************** determine_specialization (tree template_
*** 1249,1254 ****
--- 1249,1255 ----
        if (TREE_CODE (fn) == TEMPLATE_DECL)
   {
     tree decl_arg_types;
+    tree fn_arg_types;

     /* DECL might be a specialization of FN.  */

*************** determine_specialization (tree template_
*** 1265,1272 ****
        The specialization f<int> is invalid but is not caught
        by get_bindings below.  */

!    if (list_length (TYPE_ARG_TYPES (TREE_TYPE (fn)))
!        != list_length (decl_arg_types))
       continue;

     /* See whether this function might be a specialization of this
--- 1266,1281 ----
        The specialization f<int> is invalid but is not caught
        by get_bindings below.  */

!    fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn));
!    if (list_length (fn_arg_types) != list_length (decl_arg_types))
!      continue;
!
!    /* For a non-static member function, we need to make sure that
!       the const qualification is the same. This can be done by
!       checking the 'this' in the argument list.  */
!    if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
!        && !comptypes (TREE_VALUE (fn_arg_types),
!         TREE_VALUE (decl_arg_types), COMPARE_STRICT))
       continue;

     /* See whether this function might be a specialization of this



// { dg-do compile }
// Contributed by: Wolfgang Bangerth <bangerth at dealii dot org>
// PR c++/14409: Accepts invalid function signature for explicit instantiation

struct X
{
    template <typename U>
    void foo (U) {}

    template <typename U>
    void foo_const (U) const {}
};

template void X::foo (int);
template void X::foo_const (int) const;

template void X::foo (int) const;   // { dg-error "" }
template void X::foo_const (int);   // { dg-error "" }



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