User error or g++ disambiguation bug?

Discussion in 'C Programming' started by Nomen Nescio, Aug 21, 2007.

  1. Nomen Nescio

    Nomen Nescio Guest

    Hello,

    If anyone can give me some insight as to why this code fails to compile, I would be most appreciative. I have only been able to test it with gcc 3.4.4 and gcc 4.2.1, which both fail with different errors (details below).

    //////// begin test_bug.cpp

    // Standard Type2Type from Alexandrescu's Modern C++ Design
    template<typename T>
    struct Type2Type
    {
    typedef T OriginalType;
    };

    // Base for mix-in classes
    template<typename Mixin>
    struct MixinBase
    {
    virtual ~MixinBase() {}
    virtual void mixinVirtual() {}

    static void mixinStatic(Type2Type<Mixin>) {}
    };

    struct MixinA
    : public MixinBase<MixinA>
    {
    };

    struct MixinB
    : public MixinBase<MixinB>
    {
    };

    // Base for mix-in classes in an object
    template<typename ObjType, typename Mixin>
    struct ObjMixin
    : public Mixin
    {
    void mixinVirtual()
    {
    ObjType::mixinStatic(Type2Type<Mixin>());
    }
    };

    // Object composed of two mix-in classes
    struct TestObj
    : public ObjMixin<TestObj, MixinA>
    , public ObjMixin<TestObj, MixinB>
    {
    } testInstance;

    //////// end test_bug.cpp

    g++ 4.2.1 rejects this with the following output:
    ----------
    % g++ test_bug.cpp
    test_bug.cpp: In member function 'void ObjMixin<ObjType, Mixin>::mixinVirtual() [with ObjType = TestObj, Mixin = MixinA]':
    test_bug.cpp:44: instantiated from here
    test_bug.cpp:35: error: reference to 'TestObj::mixinStatic' is ambiguous
    test_bug.cpp:15: error: candidates are: static void MixinBase<Mixin>::mixinStatic(Type2Type<Mixin>) [with Mixin = MixinB]
    test_bug.cpp:15: error: static void MixinBase<Mixin>::mixinStatic(Type2Type<Mixin>) [with Mixin = MixinA]
    test_bug.cpp: In member function 'void ObjMixin<ObjType, Mixin>::mixinVirtual() [with ObjType = TestObj, Mixin = MixinB]':
    test_bug.cpp:44: instantiated from here
    test_bug.cpp:35: error: reference to 'TestObj::mixinStatic' is ambiguous
    test_bug.cpp:15: error: candidates are: static void MixinBase<Mixin>::mixinStatic(Type2Type<Mixin>) [with Mixin = MixinB]
    test_bug.cpp:15: error: static void MixinBase<Mixin>::mixinStatic(Type2Type<Mixin>) [with Mixin = MixinA]
    ----------

    This would at least appear to be wrong, since the different values for Mixin (MixinA and MixinB) should disambiguate the call.


    g++ 3.4.4 rejects it with the following output:
    ----------
    > g++ test_bug.cpp

    test_bug.cpp: In member function `void ObjMixin<ObjType, Mixin>::mixinVirtual() [with ObjType = TestObj, Mixin = MixinA]':
    test_bug.cpp:40: instantiated from here
    test_bug.cpp:32: error: `mixinStatic' is not a member of `TestObj'
    test_bug.cpp: In member function `void ObjMixin<ObjType, Mixin>::mixinVirtual() [with ObjType = TestObj, Mixin = MixinB]':
    test_bug.cpp:40: instantiated from here
    test_bug.cpp:32: error: `mixinStatic' is not a member of `TestObj'
    ----------

    Again this seems wrong, removing ObjMixin<TestObj, MixinB> from the definition of TestObj results in correct compilation under both versions, so clearly mixinStatic is found as a member of TestObj in some cases.

    Thanks in advance for any insight into what could be going on here.
     
    Nomen Nescio, Aug 21, 2007
    #1
    1. Advertising

  2. Nomen Nescio

    Mark Bluemel Guest

    Nomen Nescio wrote:

    <snip>

    > //////// begin test_bug.cpp


    I think you need the C++ newsgroup - try comp.lang.c++
     
    Mark Bluemel, Aug 21, 2007
    #2
    1. Advertising

  3. Nomen Nescio <> writes:
    > If anyone can give me some insight as to why this code fails to
    > compile, I would be most appreciative. I have only been able to test
    > it with gcc 3.4.4 and gcc 4.2.1, which both fail with different
    > errors (details below).
    >
    > //////// begin test_bug.cpp
    >
    > // Standard Type2Type from Alexandrescu's Modern C++ Design
    > template<typename T>

    [snip]

    Your code is C++, not C, so you should post to comp.lang.c++, not
    comp.lang.c.

    You also cross-posted to gnu.g.bug; I think you want gnu.g++.bug.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Aug 21, 2007
    #3
  4. Nomen Nescio

    Guest

    On Aug 21, 3:38 am, Keith Thompson <> wrote:
    [snip]
    > Your code is C++, not C, so you should post to comp.lang.c++, not
    > comp.lang.c.
    >
    > You also cross-posted to gnu.g.bug; I think you want gnu.g++.bug.


    My apologies, I used a random web form to submit the post and
    apparently it failed to properly encode the ++ in both c++ and g++ in
    the process.
     
    , Aug 21, 2007
    #4
  5. writes:
    > On Aug 21, 3:38 am, Keith Thompson <> wrote:
    > [snip]
    >> Your code is C++, not C, so you should post to comp.lang.c++, not
    >> comp.lang.c.
    >>
    >> You also cross-posted to gnu.g.bug; I think you want gnu.g++.bug.

    >
    > My apologies, I used a random web form to submit the post and
    > apparently it failed to properly encode the ++ in both c++ and g++ in
    > the process.


    Apparently there are interfaces worse than Google Groups. :cool:}

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Aug 21, 2007
    #5
  6. Nomen Nescio

    Default User Guest

    Keith Thompson wrote:

    > writes:
    > > On Aug 21, 3:38 am, Keith Thompson <> wrote:
    > > [snip]
    > >> Your code is C++, not C, so you should post to comp.lang.c++, not
    > >> comp.lang.c.
    > > >
    > >> You also cross-posted to gnu.g.bug; I think you want gnu.g++.bug.

    > >
    > > My apologies, I used a random web form to submit the post and
    > > apparently it failed to properly encode the ++ in both c++ and g++
    > > in the process.

    >
    > Apparently there are interfaces worse than Google Groups. :cool:}



    I think that using a random web form and getting this close is pretty
    amazing.




    Brian
     
    Default User, Aug 21, 2007
    #6
  7. Re: [OT] User error or g++ disambiguation bug?

    "Default User" <> writes:
    > Keith Thompson wrote:
    >> writes:
    >> > On Aug 21, 3:38 am, Keith Thompson <> wrote:
    >> > [snip]
    >> >> Your code is C++, not C, so you should post to comp.lang.c++, not
    >> >> comp.lang.c.
    >> > >
    >> >> You also cross-posted to gnu.g.bug; I think you want gnu.g++.bug.
    >> >
    >> > My apologies, I used a random web form to submit the post and
    >> > apparently it failed to properly encode the ++ in both c++ and g++
    >> > in the process.

    >>
    >> Apparently there are interfaces worse than Google Groups. :cool:}

    >
    > I think that using a random web form and getting this close is pretty
    > amazing.


    I suspect it was only a pseudo-random web form.

    Hmm, a truly random web form might be interesting, though not in any
    useful way.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Aug 21, 2007
    #7
  8. Nomen Nescio

    Default User Guest

    Re: [OT] User error or g++ disambiguation bug?

    Keith Thompson wrote:

    > "Default User" <> writes:
    > > Keith Thompson wrote:
    > >> writes:
    > >> > On Aug 21, 3:38 am, Keith Thompson <> wrote:
    > >> > [snip]
    > >> >> Your code is C++, not C, so you should post to comp.lang.c++,

    > not >> >> comp.lang.c.
    > >> > >
    > >> >> You also cross-posted to gnu.g.bug; I think you want

    > gnu.g++.bug. >> >
    > >> > My apologies, I used a random web form to submit the post and
    > >> > apparently it failed to properly encode the ++ in both c++ and

    > g++ >> > in the process.
    > >>
    > >> Apparently there are interfaces worse than Google Groups. :cool:}

    > >
    > > I think that using a random web form and getting this close is
    > > pretty amazing.

    >
    > I suspect it was only a pseudo-random web form.


    Still, getting to a programming newsgroup rather than, say, buying
    tickets to a Beatles tribute band is pretty good.

    > Hmm, a truly random web form might be interesting, though not in any
    > useful way.


    Oh crap, that one went to the "Hawt Gurlz in Pink Sox" forum. Probably
    won't get too many useful answers.




    Brian
     
    Default User, Aug 21, 2007
    #8
  9. Nomen Nescio

    Old Wolf Guest

    On Aug 22, 7:27 am, Keith Thompson <> wrote:
    >
    > Apparently there are interfaces worse than Google Groups. :cool:}


    Barely. On the side-bar as I read this thread, are three
    "Sponsored Links" (urls omitted):
    [[Give Her More to Swallow]] Fill mouths with 500% bigger loads
    Top semen volumizers reviewed

    [[She Loves To Swallow]] See girls take a mouthful and swish
    it all down--they love the stuff!

    [[Load My Mouth]] First they get a big mouth full, then they
    swallow every drop!

    These ads appear to be selected based on the message content;
    normally I get ads for C flowchart tools or network analyzer
    programs etc. I wonder what it was in this thread that triggered
    those ads! In fact I might complain about it, as it is NSFW.
     
    Old Wolf, Aug 24, 2007
    #9
  10. Nomen Nescio

    pete Guest

    [ot]Re: User error or g++ disambiguation bug?

    Old Wolf wrote:
    >
    > On Aug 22, 7:27 am, Keith Thompson <> wrote:
    > >
    > > Apparently there are interfaces worse than Google Groups. :cool:}

    >
    > Barely. On the side-bar as I read this thread, are three
    > "Sponsored Links" (urls omitted):
    > [[Give Her More to Swallow]] Fill mouths with 500% bigger loads
    > Top semen volumizers reviewed
    >
    > [[She Loves To Swallow]] See girls take a mouthful and swish
    > it all down--they love the stuff!
    >
    > [[Load My Mouth]] First they get a big mouth full, then they
    > swallow every drop!
    >
    > These ads appear to be selected based on the message content;
    > normally I get ads for C flowchart tools or network analyzer
    > programs etc. I wonder what it was in this thread that triggered
    > those ads! In fact I might complain about it, as it is NSFW.


    Sometimes, when I'm using a friend's grandkids' computer,
    a section of a clc thread on google groups,
    will be blocked by "parental controls".

    --
    pete
     
    pete, Aug 24, 2007
    #10
  11. Nomen Nescio

    CBFalconer Guest

    Old Wolf wrote:
    > Keith Thompson <> wrote:
    >
    >> Apparently there are interfaces worse than Google Groups. :cool:}

    >
    > Barely. On the side-bar as I read this thread, are three
    > "Sponsored Links" (urls omitted):
    > [[Give Her More to Swallow]] Fill mouths with 500% bigger loads
    > Top semen volumizers reviewed
    >
    > [[She Loves To Swallow]] See girls take a mouthful and swish
    > it all down--they love the stuff!
    >
    > [[Load My Mouth]] First they get a big mouth full, then they
    > swallow every drop!
    >
    > These ads appear to be selected based on the message content;
    > normally I get ads for C flowchart tools or network analyzer
    > programs etc. I wonder what it was in this thread that triggered
    > those ads! In fact I might complain about it, as it is NSFW.


    As I understand it, Googol is very proud of the fact that they
    dispense ads dependant on the historical interests of the user!
    :) What have you been researching?

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Aug 24, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xenos
    Replies:
    2
    Views:
    706
    Dave Moore
    Apr 29, 2004
  2. John Collins

    Template disambiguation

    John Collins, Dec 28, 2004, in forum: C++
    Replies:
    1
    Views:
    474
    Victor Bazarov
    Dec 29, 2004
  3. =?windows-1250?Q?Petr_Jake=9A?=
    Replies:
    11
    Views:
    1,545
  4. Replies:
    1
    Views:
    344
    Duane Hebert
    Aug 21, 2007
  5. bonzo
    Replies:
    1
    Views:
    336
    bonzo
    Oct 15, 2008
Loading...

Share This Page