This is the mail archive of the gcc-bugs@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]

[Bug c++/14337] New: function overload rules don't handle the caller as a template


The overload rules for template functions don't seem to be obeyed when the 
caller is himself a template. I noticed this because I use the trick mentioned 
here: http://m17n.org/martin/writings/template-parameter-constraints.html :a 
_lot_ in my code ;). An example that fails to compile follows. Notice that if 
you change the template on the foo(Hello<...>) function to be a static type 
(such as by moving the comment from the typedef line to the template line) then 
the code compiles fine. I last tried this with the 3.4 branch of cvs from last 
night.

template <bool Test_, typename Type_>
struct Constraint;

template <typename Type_>
struct Constraint<true, Type_> {
    typedef Type_ Result;
};

template <typename Type_>
struct IsGood {
    static const bool value = false;
};

template <>
struct IsGood<unsigned> {
    static const bool value = true;
};

template <typename Type_>
typename Constraint<IsGood<Type_>::value, void>::Result foo(Type_ &value) {
}

template <typename Type_>
typename Constraint<!IsGood<Type_>::value, void>::Result foo(Type_ &value) {
}

template <typename Type_>
class Hello {
};

// switch this template to the typedef and the code will work
//typedef int Member_;
template <typename Member_>

void foo(Hello<Member_> &value) {
    unsigned size;
    foo(size);
}

int main() {
    return 0;
}

-- 
           Summary: function overload rules don't handle the caller as a
                    template
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: saurik at saurik dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14337


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