Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > User error or g++ disambiguation bug?

Reply
Thread Tools

User error or g++ disambiguation bug?

 
 
spamfree@mailinator.com
Guest
Posts: n/a
 
      08-21-2007
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()
{
// Call mixinStatic in our base object (the one that derives
from us)
// This should call the function defined in ObjType itself if
one exists
// or the default in MixinBase if not (behavior similar to a
virtual function
// but without the actual dynamic dispatch).
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.

 
Reply With Quote
 
 
 
 
Duane Hebert
Guest
Posts: n/a
 
      08-21-2007

<> wrote in message
news: ups.com...
> 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()
> {
> // Call mixinStatic in our base object (the one that derives
> from us)
> // This should call the function defined in ObjType itself if
> one exists
> // or the default in MixinBase if not (behavior similar to a
> virtual function
> // but without the actual dynamic dispatch).
> 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.


Fails Comeau online compiler as well but the error messages may
be a bit clearer:


Comeau C/C++ 4.3.9 (Mar 27 2007 17:24:47) for ONLINE_EVALUATION_BETA1
Copyright 1988-2007 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions

"ComeauTest.c", line 34: error: "MixinBase<Mixin>::mixinStatic [with
Mixin=MixinA]"
is ambiguous
ObjType::mixinStatic(Type2Type<Mixin>());
^
detected during instantiation of "void ObjMixin<ObjType,
Mixin>::mixinVirtual() [with ObjType=TestObj,
Mixin=MixinA]"

"ComeauTest.c", line 34: error: "MixinBase<Mixin>::mixinStatic [with
Mixin=MixinA]"
is ambiguous
ObjType::mixinStatic(Type2Type<Mixin>());
^
detected during instantiation of "void ObjMixin<ObjType,
Mixin>::mixinVirtual() [with ObjType=TestObj,
Mixin=MixinB]"

2 errors detected in the compilation of "ComeauTest.c".
In strict mode, with -tused, Compile failed


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
out of class declaration virtual function disambiguation bonzo C++ 1 10-15-2008 10:33 AM
User error or g++ disambiguation bug? Nomen Nescio C Programming 10 08-24-2007 03:49 AM
technique to enter text using a mobile phone keypad (T9dictionary-based disambiguation) =?windows-1250?Q?Petr_Jake=9A?= Python 11 08-10-2006 11:32 AM
Template disambiguation John Collins C++ 1 12-29-2004 01:40 AM
template and disambiguation Xenos C++ 2 04-29-2004 10:03 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57