Bug 2065 – Return value of std.file.exists() is inverted.
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-05-02T21:29:00Z
Last change time
2015-06-09T01:21:36Z
Assigned to
andrei
Creator
torhu
Comments
Comment #0 by torhu — 2008-05-02T21:29:02Z
In r683, the Windows version of this function is changed into return the wrong value.
The correct return statement would be "return result != 0xFFFFFFFF;"
The relevant docs:
http://msdn.microsoft.com/en-us/library/aa915578.aspx
Comment #1 by andrei — 2008-05-03T11:25:54Z
(In reply to comment #0)
> In r683, the Windows version of this function is changed into return the wrong
> value.
>
> The correct return statement would be "return result != 0xFFFFFFFF;"
>
> The relevant docs:
> http://msdn.microsoft.com/en-us/library/aa915578.aspx
Ouch. How did that ever go through? The fix will go into the next release. Thanks!
Comment #2 by bugzilla — 2008-05-12T15:47:27Z
I'm having a hard time seeing how:
return (result == 0xFFFFFFFF) ? 0 : 1;
is different from:
return result != 0xFFFFFFFF;
Comment #3 by andrei — 2008-05-12T15:55:27Z
(In reply to comment #2)
> I'm having a hard time seeing how:
>
> return (result == 0xFFFFFFFF) ? 0 : 1;
>
> is different from:
>
> return result != 0xFFFFFFFF;
I see that revision 682 and before had:
return (result == 0xFFFFFFFF) ? 0 : 1;
which is correct. In revision 683 I fixed exists to return bool instead of int (just like $DEITY intended it) and in the process I introduced the bug:
return result == 0xFFFFFFFF;
The one I recently checked into dsource has:
return result != 0xFFFFFFFF;
which should fix the bug. Sorry for the mistake.
Comment #4 by caron800 — 2008-05-12T16:35:46Z
On 12/05/2008, [email protected] <[email protected]> wrote:
> I'm having a hard time seeing how:
>
> return (result == 0xFFFFFFFF) ? 0 : 1;
>
> is different from:
>
> return result != 0xFFFFFFFF;
It's certainly conceptually different. The first one returns an int,
with possible values 0 and 1. The second one returns a bool with
possible values false and true.
Comment #5 by andrei — 2008-05-12T16:41:47Z
(In reply to comment #4)
> On 12/05/2008, [email protected] <[email protected]> wrote:
> > I'm having a hard time seeing how:
> >
> > return (result == 0xFFFFFFFF) ? 0 : 1;
> >
> > is different from:
> >
> > return result != 0xFFFFFFFF;
>
> It's certainly conceptually different. The first one returns an int,
> with possible values 0 and 1. The second one returns a bool with
> possible values false and true.
>
In fact it seems the constants 0 and 1 are implicitly convertible to bool but no other integral values, which is a nice touch. I tried this program and was pleasantly surprised:
void main()
{
bool a = 0;
bool b = 1;
bool c = 2;
}
It does not compile, but it does if you remove the definition of c. This is the kind of smarts that I'd like to extend to inferring data ranges and signedness.