473,796 Members | 2,703 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 1978

<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
9474
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
1624
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
3914
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
2879
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
3914
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
9685
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
9533
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10461
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
10019
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7555
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5447
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
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
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.