www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Is it a bug?

reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
<d>
bool b() { return true; }
bool quit;
if( quit = b() ) // <---------
    return 0;
</d>

DMD 0.114 reports:
.\test.d(17): '=' does not give a boolean result

I understand the intention but statement
does have boolean result.

Am I on the right side?

Andrew Fedoniouk.
Mar 06 2005
next sibling parent reply Derek Parnell <derek psych.ward> writes:
On Sun, 6 Mar 2005 17:24:12 -0800, Andrew Fedoniouk wrote:

 <d>
 bool b() { return true; }
 bool quit;
 if( quit = b() ) // <---------
     return 0;
 </d>
 
 DMD 0.114 reports:
 .\test.d(17): '=' does not give a boolean result
 
Just a comment, but you can fix this the long way ... or the short way ... -- Derek Melbourne, Australia 7/03/2005 12:45:27 PM
Mar 06 2005
parent reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Derek Parnell schrieb am Mon, 7 Mar 2005 12:45:51 +1100:
 On Sun, 6 Mar 2005 17:24:12 -0800, Andrew Fedoniouk wrote:

 <d>
 bool b() { return true; }
 bool quit;
 if( quit = b() ) // <---------
     return 0;
 </d>
 
 DMD 0.114 reports:
 .\test.d(17): '=' does not give a boolean result
 
Just a comment, but you can fix this the long way ... or the short way ...
Where is this use of "," documented? Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCOaIh3w+/yD4P9tIRAsMGAJsG5CLaiVIfC9Ud3OppNXec5h/MnQCeOmYC 7jpaCW5NEMg++MBnJbIOab0= =l6yg -----END PGP SIGNATURE-----
Mar 17 2005
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Thomas Kuehne wrote:

Just a comment, but you can fix this the long way ...



or the short way ...


Where is this use of "," documented?
http://www.digitalmars.com/d/expression.html#Expression
 The left operand of the , is evaluated, then the right operand is
 evaluated. The type of the expression is the type of the right operand,
 and the result is the result of the right operand.
The "short" usage above is more like... gross, though ? :-) --anders
Mar 17 2005
parent Derek Parnell <derek psych.ward> writes:
On Thu, 17 Mar 2005 16:32:16 +0100, Anders F Björklund wrote:

 Thomas Kuehne wrote:
 
Just a comment, but you can fix this the long way ...



or the short way ...


Where is this use of "," documented?
http://www.digitalmars.com/d/expression.html#Expression
 The left operand of the , is evaluated, then the right operand is
 evaluated. The type of the expression is the type of the right operand,
 and the result is the result of the right operand.
The "short" usage above is more like... gross, though ? :-)
Oh absolutely. I'd shoot anyone in my teams who'd try to get away with that. I just wanted to highlight that DMD is not catching all the possible ways you can (ab)use the 'if (A = B)' idiom. -- Derek Parnell Melbourne, Australia 18/03/2005 7:50:41 AM
Mar 17 2005
prev sibling parent reply zwang <nehzgnaw gmail.com> writes:
This is a very annoying "feature" of dmd -- a blatant discrimination of 
<AssignExpression>!


Andrew Fedoniouk wrote:
 <d>
 bool b() { return true; }
 bool quit;
 if( quit = b() ) // <---------
     return 0;
 </d>
 
 DMD 0.114 reports:
 .\test.d(17): '=' does not give a boolean result
 
 I understand the intention but statement
 does have boolean result.
 
 Am I on the right side?
 
 Andrew Fedoniouk.
Mar 06 2005
parent reply Nick <Nick_member pathlink.com> writes:
Personally I like the feature, just not the error message, which, as Andrew
demonstrates, claims something that is clearly not true.

Nick

In article <d0ggi4$1b9v$1 digitaldaemon.com>, zwang says...
This is a very annoying "feature" of dmd -- a blatant discrimination of 
<AssignExpression>!


Andrew Fedoniouk wrote:
 <d>
 bool b() { return true; }
 bool quit;
 if( quit = b() ) // <---------
     return 0;
 </d>
 
 DMD 0.114 reports:
 .\test.d(17): '=' does not give a boolean result
 
 I understand the intention but statement
 does have boolean result.
 
 Am I on the right side?
 
 Andrew Fedoniouk.
Mar 07 2005
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Nick wrote:

.\test.d(17): '=' does not give a boolean result
This is a very annoying "feature" of dmd -- a blatant discrimination of 
<AssignExpression>!
 Personally I like the feature, just not the error message, which, as Andrew
 demonstrates, claims something that is clearly not true.
As long as 'true' is an integer 1, it's actually somewhat correct ;-) And you should almost always write those "if" expressions out anyway... If not by using two statements, then at least with an extra parenthesis. --anders
Mar 07 2005