Bug 5165 – compiler add a cast and then complain that the cast have no effect, giving no .o file
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
Other
OS
Linux
Creation time
2010-11-04T18:33:00Z
Last change time
2010-12-30T22:13:40Z
Assigned to
nobody
Creator
dufresnep
Comments
Comment #0 by dufresnep — 2010-11-04T18:33:30Z
I try to compile, with dmd 1.065 the following:
---
struct u64_t{
uint lo;
uint hi;
};
bool is_zero64(u64_t i) {i.hi==0 && i.lo==0;}
---
but I get:
[paul@Arcturus ~]$ dmd -c test.d
test.d(7): Error: == has no effect in expression (i.lo == cast(uint)0)
test.d(7): Error: function test.is_zero64 expected to return a value of type bool
[paul@Arcturus ~]$
and I don't seems to find a way to rewrite this without the compiler refusing it.
Comment #1 by ellery-newcomer — 2010-11-04T18:47:15Z
(In reply to comment #0)
> I try to compile, with dmd 1.065 the following:
>
> ---
> struct u64_t{
> uint lo;
> uint hi;
> };
>
> bool is_zero64(u64_t i) {i.hi==0 && i.lo==0;}
> ---
>
> but I get:
> [paul@Arcturus ~]$ dmd -c test.d
> test.d(7): Error: == has no effect in expression (i.lo == cast(uint)0)
> test.d(7): Error: function test.is_zero64 expected to return a value of type
> bool
> [paul@Arcturus ~]$
>
> and I don't seems to find a way to rewrite this without the compiler refusing
> it.
sure you didn't mean
bool is_zero64(u64_t i) {return i.hi==0 && i.lo==0;}
?
Comment #2 by dufresnep — 2010-11-04T18:53:18Z
You are right...
I had come to think that the value returned by a function was the last expression evaluated, and then concluded that the return could be removed... but it seems it is not true.