Thread overview
[Issue 5165] New: compiler add a cast and then complain that the cast have no effect, giving no .o file
Nov 05, 2010
Paul Dufresne
Nov 05, 2010
Ellery Newcomer
Nov 05, 2010
Paul Dufresne
Dec 31, 2010
Don
November 05, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5165

           Summary: compiler add a cast and then complain that the cast
                    have no effect, giving no .o file
           Product: D
           Version: D1
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: dufresnep@gmail.com


--- Comment #0 from Paul Dufresne <dufresnep@gmail.com> 2010-11-04 18:33:30 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 05, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5165


Ellery Newcomer <ellery-newcomer@utulsa.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ellery-newcomer@utulsa.edu


--- Comment #1 from Ellery Newcomer <ellery-newcomer@utulsa.edu> 2010-11-04 18:47:15 PDT ---
(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;}

?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 05, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5165



--- Comment #2 from Paul Dufresne <dufresnep@gmail.com> 2010-11-04 18:53:18 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 31, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5165


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug@yahoo.com.au
         Resolution|                            |INVALID


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------