473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

User error or g++ disambiguation bug?

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, 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.

Aug 21 '07 #1
1 1944

<sp******@mailinator.comwrote in message
news:11*********************@x35g2000prf.googlegro 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, 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.
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
Aug 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Therese A. Sorna | last post by:
Hello all... I am using Access 2002. I have database set to add users names to the user level security when they are added to a particular table in a database, using the Catalog and...
4
by: patrick_a | last post by:
Hello, I am trying to insert multiple instances of a custom user control into a placeholder on an aspx page, based on the records retrieved from the database. I use the datareader to loop through...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
4
by: Prince Mathew | last post by:
Hi All, I have a requirement. I am throwing an exception from the Page_Load of my user control I want to catch this in my container page. Is this possible? The Page_Load of user control is...
6
by: Yan | last post by:
Here is the code: class A {}; void (A::*A) (); // Line 3 int main() { A a; // Line 6 return 0; }
6
by: Tashfeen Bhimdi | last post by:
I'm trying to remove punctuation from a string with the following code: ---------------------------- #include <string> #include <algorithm> #include <cctype> .. using namespace std ..
7
by: zhouchengly | last post by:
when I use the following code to get integer values from file: void getIntegers() { vector<ItemType items; ifstream ifs("test.dat"); //¿¼ÂÇΪitemsÒ»´Î·ÖÅä¿Õ¼ä¡£ ItemType item ; while(...
5
by: PLS | last post by:
I'm converting some C++ code to VC++ 2005 in native (non-managed) mode. This code doesn't use ATL, but codes the COM mechanisms directly. It has a class which is the equivalent of ATL's...
7
by: Nomen Nescio | last post by:
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...
63
by: Kapteyn's Star | last post by:
Hi newsgroup The program here given is refused by GCC with a error i cannot understand. It says rnd00.c: In function ‘main’: rnd00.c:26: error: expected expression before ‘]’ token ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.