473,785 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<typena me T>
struct Type2Type
{
typedef T OriginalType;
};

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

static void mixinStatic(Typ e2Type<Mixin>) {}
};

struct MixinA
: public MixinBase<Mixin A>
{
};

struct MixinB
: public MixinBase<Mixin B>
{
};

// Base for mix-in classes in an object
template<typena me 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::mixinS tatic(Type2Type <Mixin>());
}
};

// Object composed of two mix-in classes
struct TestObj
: public ObjMixin<TestOb j, MixinA>
, public ObjMixin<TestOb j, 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<ObjTyp e,
Mixin>::mixinVi rtual() [with ObjType = TestObj, Mixin = MixinA]':
test_bug.cpp:44 : instantiated from here
test_bug.cpp:35 : error: reference to 'TestObj::mixin Static' 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<ObjTyp e,
Mixin>::mixinVi rtual() [with ObjType = TestObj, Mixin = MixinB]':
test_bug.cpp:44 : instantiated from here
test_bug.cpp:35 : error: reference to 'TestObj::mixin Static' 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<ObjTyp e,
Mixin>::mixinVi rtual() [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<ObjTyp e,
Mixin>::mixinVi rtual() [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<TestOb j, 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 1977

<sp******@maili nator.comwrote in message
news:11******** *************@x 35g2000prf.goog legroups.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<typena me T>
struct Type2Type
{
typedef T OriginalType;
};

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

static void mixinStatic(Typ e2Type<Mixin>) {}
};

struct MixinA
: public MixinBase<Mixin A>
{
};

struct MixinB
: public MixinBase<Mixin B>
{
};

// Base for mix-in classes in an object
template<typena me 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::mixinS tatic(Type2Type <Mixin>());
}
};

// Object composed of two mix-in classes
struct TestObj
: public ObjMixin<TestOb j, MixinA>
, public ObjMixin<TestOb j, 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<ObjTyp e,
Mixin>::mixinVi rtual() [with ObjType = TestObj, Mixin = MixinA]':
test_bug.cpp:44 : instantiated from here
test_bug.cpp:35 : error: reference to 'TestObj::mixin Static' 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<ObjTyp e,
Mixin>::mixinVi rtual() [with ObjType = TestObj, Mixin = MixinB]':
test_bug.cpp:44 : instantiated from here
test_bug.cpp:35 : error: reference to 'TestObj::mixin Static' 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<ObjTyp e,
Mixin>::mixinVi rtual() [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<ObjTyp e,
Mixin>::mixinVi rtual() [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<TestOb j, 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_EVALUATI ON_BETA1
Copyright 1988-2007 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extension s

"ComeauTest .c", line 34: error: "MixinBase<Mixi n>::mixinStati c [with
Mixin=MixinA]"
is ambiguous
ObjType::mixinS tatic(Type2Type <Mixin>());
^
detected during instantiation of "void ObjMixin<ObjTyp e,
Mixin>::mixinVi rtual() [with ObjType=TestObj ,
Mixin=MixinA]"

"ComeauTest .c", line 34: error: "MixinBase<Mixi n>::mixinStati c [with
Mixin=MixinA]"
is ambiguous
ObjType::mixinS tatic(Type2Type <Mixin>());
^
detected during instantiation of "void ObjMixin<ObjTyp e,
Mixin>::mixinVi rtual() [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
2439
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 ActiveConnection commands. I am getting errors when I try to add a name that is already in the database. I was wondering if anyone knew of a way to have it check for the user's name before going to add it? One method would be to delete everytime before...
4
8803
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 the records and I want to create a new instance of the user control for each record and then change the properties of the controls within each user control. The problem is that after I create the new instance of the user control, I get a...
8
9469
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 System.Security.Principal.WindowsImpersonationContext Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
4
1623
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 executed after the Page_Load of the page. So we cannot catch this in the Page_Load of the page. So my question where in the page i will catch the exception thrown form the user control. I don't want any event to be raised from the user control.
6
1915
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
3706
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
3912
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( !ifs.eof() ) { ifs>>item;
5
2878
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 IDispatchImpl: template<class T> class CDispatch : virtual public IDispatch, virtual public CUnknown, private CDispatchBase { ...
7
353
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 different errors (details below). //////// begin test_bug.cpp // Standard Type2Type from Alexandrescu's Modern C++ Design template<typename T> struct Type2Type {
63
3911
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 How to make it compile? I also tried buf but that gives "segmentation fault". Thanks in advanced.
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10350
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10097
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8983
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.