473,387 Members | 1,687 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,387 software developers and data experts.

Comeau and G++ disagree. Compiler bug?

Hi,

I was trying to come up with obscure C++ questions in the style of GoTW
and ran across this unexpected difference between G++ and comeau. Can
anyone point me in the direction of the correct result for this program?
#include <iostream>

namespace A {
class Foo { };
struct f {
public:
f(const Foo& f) { std::cout << "ctor" << std::endl; }
};
}

template <typename T>
void f(const T& t) { std::cout << "Template ref" << std::endl; }

void f(A::Foo& f) { std::cout << "Plain ref" << std::endl; }

int main() {
f(A::Foo());
return 0;
}

G++ doesn't accept it and says:
test.cc: In function 'int main()':
test.cc:5: error: 'struct A::f' is not a function,
test.cc:14: error: conflict with 'void f(A::Foo&)'
test.cc:17: error: in call to 'f'
G++ version was:
g++ (GCC) 4.1.3 20070718 (prerelease) (Debian 4.1.2-14)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Whereas Comeau allows it (I only tried it online, so I don't for certain
know what f(A::Foo()); actually resolved to. Comeau version was:
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++ noC++0x_extensions

Thanks,
Alan
Aug 12 '07 #1
4 1642
On Aug 12, 11:57 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Alan Woodland wrote:
I'll be filing a bug against g++ shortly given that g++ (GCC) 4.3.0
20070720 also seems to have this problem.
I would wait a couple of days... I have a sneaky feeling James Kanze
will want to chime in. <g>
Obviously:-). In this case, I don't find the standard as clear
as you do (but your interpretation is definitly one possible
one, and probably the intended one), so I wouldn't treat g++ too
harshly; they may just have interpreted the standard
differently. The current draft, however, adds an additional
qualification to ADL which says, literally "All names except
those of (possibly overloaded) functions and function templates
are ignored." So I'm sure that whatever the original reasons
why g++ behaves as it does, they'll want to change it to conform
to what the future standard will say.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Aug 13 '07 #2
James Kanze wrote:
On Aug 12, 11:57 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>Alan Woodland wrote:
>>I'll be filing a bug against g++ shortly given that g++ (GCC) 4.3.0
20070720 also seems to have this problem.
>I would wait a couple of days... I have a sneaky feeling James Kanze
will want to chime in. <g>

Obviously:-). In this case, I don't find the standard as clear
as you do (but your interpretation is definitly one possible
one, and probably the intended one), so I wouldn't treat g++ too
harshly; they may just have interpreted the standard
differently. The current draft, however, adds an additional
qualification to ADL which says, literally "All names except
those of (possibly overloaded) functions and function templates
are ignored." So I'm sure that whatever the original reasons
why g++ behaves as it does, they'll want to change it to conform
to what the future standard will say.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
I think we're all grateful for both Victor and James. They both make a
lot of valuable contributions to this newsgroup. As for the G++ compiler
flagging an error, that is what I would have expected, and I'm indebted
to Victor and James for pointing out the lack of clarity in the current
C++ standard on this point. Keep up the good work, I certainly
appreciate it and hopefully it improves my C++ knowledge reading the
feedback given on this newsgroup.

JB
Aug 13 '07 #3
On Aug 13, 2:04 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:

[...]
According to the new draft, if 'f' were an object with an overloaded
function call operator:
namespace A {
class Foo { };
struct ff {
public:
void operator()(const Foo&)
{ std::cout << "operator()" << std::endl; }
} f;
}
void f(const A::Foo&) { std::cout << "regular func" << std::endl; }
int main() {
f(A::Foo());
return 0;
}
, it wouldn't have been found either, but I am not sure about the
current wording (or GNU folks' interpretation of it). I don't have
G++ to try this one, but VC++ and Comeau online accept it.
That's a good point. I think that in the current standard, that
is clearly legal. The fact that the draft makes it illegal
could break some code, and possibly wasn't intended. Maybe
someone should raise the point in comp.std.c++. (I'm leaving on
vacation very shortly, and will be off line for close to three
weeks, or I'd do it myself.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Aug 13 '07 #4
James Kanze wrote:
On Aug 13, 2:04 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:

[...]
>According to the new draft, if 'f' were an object with an overloaded
function call operator:
> namespace A {
class Foo { };
struct ff {
public:
void operator()(const Foo&)
{ std::cout << "operator()" << std::endl; }
} f;
}
> void f(const A::Foo&) { std::cout << "regular func" << std::endl; }
> int main() {
f(A::Foo());
return 0;
}
>, it wouldn't have been found either, but I am not sure about the
current wording (or GNU folks' interpretation of it). I don't have
G++ to try this one, but VC++ and Comeau online accept it.

That's a good point. I think that in the current standard, that
is clearly legal. The fact that the draft makes it illegal
could break some code, and possibly wasn't intended. Maybe
someone should raise the point in comp.std.c++. (I'm leaving on
vacation very shortly, and will be off line for close to three
weeks, or I'd do it myself.)
I don't believe it's so bad. Let's examine the "issue". If the
code was broken before the new Standard (the error was reported),
how would suddenly making the code working *break* anything? Are
you thinking of some SFINAE technique here?

If I remove the '::f' function from the code above, VC++ and Comeau
(the ones I can test now) do not find 'f', not sure what G++ would
do. Let's say that G++ would accept it (is that a bug?), relying
on their understanding of ADL. The new standard would then prohibit
finding 'f' since it's not a function. Fixing it should not really
be such a PITA (provided G++ folks do implement the new Standard
correctly after it's adopted), and they could still provide their
old behaviour as another extension <g>.

I'll post the question in comp.std.c++.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 13 '07 #5

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

Similar topics

7
by: Bob Hairgrove | last post by:
Hi, The Digital Mars compiler is not listed on the Dinkumware library's compatibility list on their web site. I would like to use the Dinkumware STL (source code license) together with the...
9
by: Theodore Huxibolde | last post by:
The Comeau C++ web site does not appear to have been updated in nearly a year, but I do notice that Mr. Comeau does post here quite freqently. Is this compiler still being actively developed and...
12
by: nicdude | last post by:
There is a Comeau C++ compiler special offer at http://www.comeaucomputing.com Is it really as compliant as it seems to imply? In terms of Standard C++, what is it missing? Can it handle...
4
by: Axter | last post by:
Sorry for OT question, but does any one have a working *.bat file to get Comeau to work with VC++ 7.1, VC++ 8.0, or GNU 3.x compilers. I've tried everything I can think off, to get it to work,...
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
4
by: Alan Woodland | last post by:
I've been trying out more template metaprogramming ideas with typelists (mostly for personal learning, I'm aware boost most probably provides this facility already), and I've run into this small...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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...

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.