Board index » cppbuilder » Comeau differs from BCC

Comeau differs from BCC


2007-04-20 12:47:53 AM
cppbuilder10
And I think BCC is correct:
For this code BCC gives the error about multiple declarations
class test {
public:
operator bool();
operator const bool();
};
Comeau just says that const is meaningless. But once const is removed,
Comeau gives an error.
Your thoughts?
 
 

Re:Comeau differs from BCC

"Alex Bakaev [TeamB]" < XXXX@XXXXX.COM >writes:
Quote
And I think BCC is correct:

For this code BCC gives the error about multiple declarations

class test {
public:
operator bool();
operator const bool();
};


Comeau just says that const is meaningless. But once const is removed,
Comeau gives an error.

Your thoughts?
If you remove "const", you're left with two operator bool() members,
which is an error. If you remove the entire function declaration,
then it should be allowed.
But it is ambiguous to have both, as both bool and "const bool" can be
initialized by either a bool or "const bool". Outermost constness on
types is somewhat unmeaningful. For example:
void foo(int x) { }
void foo(int const x) { } // error: foo(int) already defined
--
Chris (TeamB);
 

Re:Comeau differs from BCC

Quote

If you remove "const", you're left with two operator bool() members,
which is an error. If you remove the entire function declaration,
then it should be allowed.

So should Comeau give an error for the code as supplied? It does give a
warning:
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 4: warning: type qualifier on return type is
meaningless
operator const bool() ;
 

{smallsort}

Re:Comeau differs from BCC

"Alex Bakaev [TeamB]" < XXXX@XXXXX.COM >wrote:
Quote
So should Comeau give an error for the code as supplied? It does give a
warning:

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 4: warning: type qualifier on return type is
meaningless
operator const bool() ;
It should give 'a diagnostic' (the standard doesn't actually specify
'errors' or 'warnings'). Which it does.
As a QoI issue, yes, it really should be an error, though I suspect that
any actual call would turn out to be ambiguous. If you do clear up the
issue on which it is supplying a warning (and you do clear up all
warnings, don't you (-:), then the warning will become an error.
Comeau isn't automatically correct every time it conflicts with BCC -
just mostly.
Alan Bellingham
--
ACCU Conference 2008: 2-5 April 2008 - Oxford (probably), UK
 

Re:Comeau differs from BCC

In article <46279d38$ XXXX@XXXXX.COM >,
Alex Bakaev [TeamB] < XXXX@XXXXX.COM >wrote:
Quote
And I think BCC is correct:

For this code BCC gives the error about multiple declarations

class test {
public:
operator bool();
operator const bool();
};


Comeau just says that const is meaningless. But once const is removed,
Comeau gives an error.

Your thoughts?
Clearly the above case is eventually asking for trouble as is.
Don't ask me to look this up, but IIRC correctly it's ill-formed.
As you note, Comeau does emit a warming. It can also be made into
an error via --diag_error=815. The reason for the warning "first"
is two'ish-fold: a) the above is just a declaration and not a use
of "either" conversion function; any said use _would_ emit an error...
you would not want the error on say a template that never gets used
and b) some uses of const on return types can make sense, again
especially in the template case, so if it were T and not bool
then the code may or may not make sense depending upon the T
eventually filled in. I agree this is not your case, but
the wiggle room is there, even though as a weak argument,
and at least the warning comes out about the const itself in this case.
--
Greg Comeau / 4.3.9 with C++0xisms now in beta!
Comeau C/C++ ONLINE ==>www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
 

Re:Comeau differs from BCC

Quote
the wiggle room is there, even though as a weak argument,
and at least the warning comes out about the const itself in this case.
Thanks Greg :)
 

Re:Comeau differs from BCC

It is a function (yes, an operator is a function). Functions may be
overloaded by calling arguments, not by return types. Borland is correct.
. Ed
Quote
Alex Bakaev wrote in message
news:46279d38$ XXXX@XXXXX.COM ...
And I think BCC is correct:

For this code BCC gives the error about multiple declarations

class test {
public:
operator bool();
operator const bool();
};


Comeau just says that const is meaningless. But once const is removed,
Comeau gives an error.

Your thoughts?
 

Re:Comeau differs from BCC

Ed Mulroy wrote:
Quote
It is a function (yes, an operator is a function). Functions may be
overloaded by calling arguments, not by return types. Borland is correct.

. Ed

Unless we are talking about covariant overload :)
.a
 

Re:Comeau differs from BCC

Greg Comeau wrote:
Quote
and b) some uses of const on return types can make sense, again
especially in the template case, so if it were T and not bool
then the code may or may not make sense depending upon the T
eventually filled in.
For what T does it make sense ?
Micha
 

Re:Comeau differs from BCC

"Alex Bakaev [TeamB]" < XXXX@XXXXX.COM >wrote:
Quote
Ed Mulroy wrote:
>It is a function (yes, an operator is a function). Functions may be
>overloaded by calling arguments, not by return types. Borland is correct.

Unless we are talking about covariant overload :)
I don't even want to think about that!
(And I don't think anyone has yet suggested it for the language, unless
it was one of the very few 'completely silly' proposals Bjarne
Stroustrup was hinting at last week.)
Alan Bellingham
--
Team Thai Kingdom
<url:www.borland.com/newsgroups/>Borland newsgroup descriptions
<url:www.borland.com/newsgroups/netiquette.html>netiquette
 

Re:Comeau differs from BCC

Alan Bellingham wrote:
Quote
(And I don't think anyone has yet suggested it for the language, unless
it was one of the very few 'completely silly' proposals Bjarne
Stroustrup was hinting at last week.)

Alan Bellingham
Yeah, he's known for doing silly things, eh? :)
 

Re:Comeau differs from BCC

Here is a follow-up question. The following code produces a syntax error
(with every compiler I tried)
class test
{
public:
test( int );
test & operator=( int );
operator int() throw();
private:
test( bool );
operator bool();
operator bool()const;
};
class test2
{
public:
test2( int );
test2( bool );
};
void f()
{
test t2( 10 );
test2 tt( t2 );
}
"ComeauTest.c", line 24: error: more than one instance of constructor
"test2::test2"
matches the argument list, the choices that match are:
function "test2::test2(int)"
function "test2::test2(bool)"
The argument types that you used are: (test)
test2 tt( t2 );
The question is:
why the test2( bool ) is considered here?
There is no conversion from test to bool. But there is a conversion from
test to int.
Thanks,
.a
 

Re:Comeau differs from BCC

"Alex Bakaev [TeamB]" < XXXX@XXXXX.COM >wrote:
Quote
There is no conversion from test to bool. But there is a conversion from
test to int.
Oh yes there is!
class test
{
public:
test( int );
test & operator=( int );
Quote
>operator int() throw();
private:
test( bool );
Quote
>operator bool();
operator bool()const;
};
Just because one is private doesn't mean it isn't considered.
Alan Bellingham
--
Team Thai Kingdom
<url:www.borland.com/newsgroups/>Borland newsgroup descriptions
<url:www.borland.com/newsgroups/netiquette.html>netiquette
 

Re:Comeau differs from BCC

Alan Bellingham wrote:
Quote

Just because one is private doesn't mean it isn't considered.
Thanks! Now I remember :)
 

Re:Comeau differs from BCC

Well, just for the completeness here, I have to report that VC++ 7.1
doesn't complain about such code. And that, in fact, seems to trigger
another VC++ bug (it doesn't flag as ambiguous the case I posted as
another reply to myself -
function "test2::test2(int)"
function "test2::test2(bool)"
}
.a