Bug 4361 - bogus ambiguity taking the address of a member template
Summary: bogus ambiguity taking the address of a member template
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.0.1
: P3 normal
Target Milestone: ---
Assignee: Nathan Sidwell
Depends on:
Reported: 2001-09-19 09:26 UTC by Martin Sebor
Modified: 2003-07-25 17:33 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2001-09-19 09:26:01 UTC
This is reduced from our auto_ptr testsuite. The compiler
is confused by the two conversion operators. 2.95.2 ICEs
on this code.


gcc 3.0.1

$ cat t.cc ; g++ t.cc
template <class T>
class auto_ptr;

template <class T>
struct auto_ptr_ref
    template <class U>
    auto_ptr_ref (auto_ptr<U>&) throw () { }

template<class T>
struct auto_ptr
    template <class U>
    operator auto_ptr_ref<U>() throw () {
        return auto_ptr_ref<U>(*this);

    template <class U>
    operator auto_ptr<U>() throw () {
        return auto_ptr<U>();

struct B { };
struct D: B { };

int main ()
    auto_ptr<B> (auto_ptr<D>::*pf)() = &auto_ptr<D>::operator auto_ptr<B>;
t.cc: In function `int main()':
t.cc:32: no matches converting function `operator auto_ptr_ref<U>' to type 
   `struct auto_ptr<B> (struct auto_ptr<D>::*)()'
t.cc:16: candidates are: template<class U> auto_ptr::operator auto_ptr_ref<U>() 
   [with U = U, T = D]
Comment 1 Nathan Sidwell 2001-12-15 10:27:45 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: yup, that looks bogus
Comment 2 Nathan Sidwell 2001-12-29 08:30:28 UTC
Responsible-Changed-From-To: unassigned->nathan
Responsible-Changed-Why: patch in progress
Comment 3 Nathan Sidwell 2002-03-16 10:30:30 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: mainline only, as this is not a regression.
    2001-12-30  Nathan Sidwell  <nathan@codesourcery.com>
            PR c++/4361
            * cp-tree.h (CLASSTYPE_METHOD_VEC): Document where templated
            conversion operators go.
            (struct lang_decl_flags): Add template_conv_p and unused
            (DECL_TEMPLATE_CONV_FN_P): New macro.
            * call.c (build_user_type_conversion_1): Don't check second type
            conversion of overload set first.
            * class.c (add_method): Make sure templated conversion operators
            all end up on slot 2.
            * lex.c (do_identifier): A conversion operator token might be
            satisfied by a templated conversion operator.
            * mangle.c (internal_mangling_p): New global variable.
            (write_template_param): Do internal mangling, if needed.
            (mangle_conv_op_name_for_type): Request internal mangling.
            * pt.c (check_explicit_specialization): Use
            (template_parm_this_level_p): New function.
            (push_template_decl_real): Determine DECL_TEMPLATE_CONV_FN_P.
            * search.c (lookup_fn_fields_1): Template conversions will be on
            the first slot.
            * typeck.c (build_component_ref): Preserve the type of an
            conversion operator name on the overload type.
            (build_x_function_call): Retrieve the conversion operator name.