[Bug c++/15480] New: ICE with sizeof(T().f()) as template parameter in function resolution

gianni at mariani dot ws gcc-bugzilla@gcc.gnu.org
Mon May 17 08:02:00 GMT 2004


Below is a template that is supposed to discover wether a type contains a method
 named "Function".

Comeau compiles this fine on Comeau C/C++ 4.3.3, fails on MSC++ 7.1 with what
seems to be the wrong error and ICE's on gcc 3.4.0.



typedef char MPT_False;

struct MPT_True { int m[2]; };


template <unsigned int w_siz>
struct MPT_IntToType
{
    typedef char    type[ w_siz ];
};

template <typename w_D>
struct MPT_Finder_Member
{
    template <typename w_T>
    static MPT_True finder(
        const w_T *,
        typename MPT_IntToType<
            sizeof(w_T().Function())
//          sizeof(static_cast<w_T>(0)->Function()) //fails same way
        >::type * = 0
    );
        
    static MPT_False finder( const w_D * );

};

template <typename w_D >
struct MPT_ContainsFuncMember
{
    struct DerivedClass : w_D
    {
    };

    typedef DerivedClass  * DerivedClassp;

    enum {
        value = (
            sizeof( MPT_Finder_Member<w_D>::finder( DerivedClassp() ) )
            == sizeof( MPT_True )
        )
    };
    
};


struct A
{
};

struct B
{
    int Function();
};

#include <iostream>

int main()
{
    std::cout << MPT_ContainsFuncMember<A>::value << "\n";
    std::cout << MPT_ContainsFuncMember<B>::value << "\n";
}

-- 
           Summary: ICE with sizeof(T().f()) as template parameter in
                    function resolution
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gianni at mariani dot ws
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-redhat-linux
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux


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



More information about the Gcc-bugs mailing list