public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/31512]  New: function template with member reference compile failure
@ 2007-04-09  6:34 gianni at mariani dot ws
  2007-04-09 12:51 ` [Bug c++/31512] " gianni at mariani dot ws
  2010-04-28 18:24 ` redi at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: gianni at mariani dot ws @ 2007-04-09  6:34 UTC (permalink / raw)
  To: gcc-bugs

The code below has 3 ways of declaring the template member function
ObjInitSelDot().  One of them performs as desired, the other two do not. 
Comeau compiles all of them (albeit with a silly warning).

As far as I can tell, all three should compile.

template <typename T>
struct InitObject
{
    private:

    struct xA {};
    struct xB : xA {};

    template <int w_size>
    struct Detect;

    struct NoMemb { char a[1]; };
    struct Memb_MemberA { char a[2]; };


    template <typename U>
    inline static Memb_MemberA ObjInitSelDot(
// 3 different signatures - one works 2 fail under gcc 4.1.1
//        U & obj, xB * b, Detect< sizeof(U().MemberA) > * = 0 // ?? bug
//        U & obj, xB * b, Detect< sizeof(&U::MemberA) > * = 0 // Works
        // also ICE's on gcc 4.0.0 and earlier
        U & obj, xB * b, Detect< sizeof(((U*)0)->MemberA) > * = 0 // ?? bug
    );

    template <typename U>
    inline static NoMemb ObjInitSelDot(
        U & obj, xA * b
    );

    public:

    inline int ObjTest()
    {
        typedef xB * bp;

        T   obj = T();

        return sizeof( ObjInitSelDot( obj, bp() ) );

    }
};


/////////// test code

struct A
{
    int a;
    char x[10];
};


struct B
{
    int MemberA;
    char x[15];
};


int main()
{
    InitObject<A>().ObjTest();
    InitObject<B>().ObjTest();
}


-- 
           Summary: function template with member reference compile failure
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gianni at mariani dot ws
 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=31512


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-04-28 18:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-09  6:34 [Bug c++/31512] New: function template with member reference compile failure gianni at mariani dot ws
2007-04-09 12:51 ` [Bug c++/31512] " gianni at mariani dot ws
2010-04-28 18:24 ` redi at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).