Connecting Tech Pros Worldwide Forums | Help | Site Map

User error or g++ disambiguation bug?

Nomen Nescio
Guest
 
Posts: n/a
#1: Aug 21 '07
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:
----------
Quote:
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, MixinBfrom 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.






Mark Bluemel
Guest
 
Posts: n/a
#2: Aug 21 '07

re: User error or g++ disambiguation bug?


Nomen Nescio wrote:

<snip>
Quote:
//////// begin test_bug.cpp
I think you need the C++ newsgroup - try comp.lang.c++
Keith Thompson
Guest
 
Posts: n/a
#3: Aug 21 '07

re: User error or g++ disambiguation bug?


Nomen Nescio <nobody@dizum.comwrites:
Quote:
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) kst-u@mib.org <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"
spamfree@mailinator.com
Guest
 
Posts: n/a
#4: Aug 21 '07

re: User error or g++ disambiguation bug?


On Aug 21, 3:38 am, Keith Thompson <ks...@mib.orgwrote:
[snip]
Quote:
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.

Keith Thompson
Guest
 
Posts: n/a
#5: Aug 21 '07

re: User error or g++ disambiguation bug?


spamfree@mailinator.com writes:
Quote:
On Aug 21, 3:38 am, Keith Thompson <ks...@mib.orgwrote:
[snip]
Quote:
>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. 8-)}

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <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"
Default User
Guest
 
Posts: n/a
#6: Aug 21 '07

re: User error or g++ disambiguation bug?


Keith Thompson wrote:
Quote:
spamfree@mailinator.com writes:
Quote:
On Aug 21, 3:38 am, Keith Thompson <ks...@mib.orgwrote:
[snip]
Quote:
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. 8-)}

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




Brian
Keith Thompson
Guest
 
Posts: n/a
#7: Aug 21 '07

re: User error or g++ disambiguation bug?


"Default User" <defaultuserbr@yahoo.comwrites:
Quote:
Keith Thompson wrote:
Quote:
>spamfree@mailinator.com writes:
Quote:
On Aug 21, 3:38 am, Keith Thompson <ks...@mib.orgwrote:
[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. 8-)}
>
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) kst-u@mib.org <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"
Default User
Guest
 
Posts: n/a
#8: Aug 21 '07

re: User error or g++ disambiguation bug?


Keith Thompson wrote:
Quote:
"Default User" <defaultuserbr@yahoo.comwrites:
Quote:
Keith Thompson wrote:
Quote:
spamfree@mailinator.com writes:
On Aug 21, 3:38 am, Keith Thompson <ks...@mib.orgwrote:
[snip]
Your code is C++, not C, so you should post to comp.lang.c++,
not >comp.lang.c.
Quote:
Quote:
>
You also cross-posted to gnu.g.bug; I think you want
gnu.g++.bug. >
Quote:
Quote:
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.
Quote:
Quote:
>
Apparently there are interfaces worse than Google Groups. 8-)}
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.
Quote:
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

Closed Thread