Thread overview
[Issue 2172] New: bool add bool accepted?
Jun 25, 2008
d-bugmail
Jun 27, 2008
d-bugmail
Jun 27, 2008
d-bugmail
Jun 30, 2008
d-bugmail
[Issue 2172] statically disallow bool + bool
Jan 30, 2012
yebblies
Jan 30, 2012
yebblies
June 25, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2172

           Summary: bool add bool accepted?
           Product: D
           Version: 1.030
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: davidl@126.com
 BugsThisDependsOn: 1511


bool t;
t= true+false;  // this accepted
t= true+true;   // Error: cannot implicitly convert expression (2) of type int
to bool

bool type shouldn't be addable.

and error message is confusing.


-- 

June 27, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2172


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #1 from bugzilla@digitalmars.com  2008-06-27 17:15 -------
bool follows the same integral promotion rules that C has, and this is working as designed. I also do not understand why the error message is confusing - 2 cannot be implicitly converted to bool, as it says.


-- 

June 27, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2172





------- Comment #2 from shro8822@vandals.uidaho.edu  2008-06-27 17:29 -------
I think the confusion comes from the cast failure being value dependent rather than just type dependent.


-- 

June 27, 2008
<d-bugmail@puremagic.com> wrote in message news:g43oq2$2k82$1@digitalmars.com...
> http://d.puremagic.com/issues/show_bug.cgi?id=2172
>
>
> bugzilla@digitalmars.com changed:
>
>           What    |Removed                     |Added
> ----------------------------------------------------------------------------
>             Status|NEW                         |RESOLVED
>         Resolution|                            |INVALID
>
>
>
>
> ------- Comment #1 from bugzilla@digitalmars.com  2008-06-27 17:15 -------
> bool follows the same integral promotion rules that C has, and this is
> working
> as designed. I also do not understand why the error message is confusing -
> 2
> cannot be implicitly converted to bool, as it says.

I can understand the OP's confusion.

http://www.digitalmars.com/d/1.0/type.html

"The only operators that can accept operands of type bool are: & | ^ &= |= ^= ! && || ?:. A bool value can be implicitly converted to any integral type, with false becoming 0 and true becoming 1."

Which one is it?  It seems that promotion to an int makes the first rule unnecessary.

Also, keep in mind that D *is* your language and you don't *have* to do everything the same way as C.  I think that having boolean types not implicitly convertible to ints makes a lot more sense.


June 30, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2172


davidl@126.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |




------- Comment #3 from davidl@126.com  2008-06-29 22:11 -------
I don't think we still need to keep consistent with C on that exactly point.
Compiler can at least giving a waring on this.
And adding code to BinExp::semantic , and provide a table like implicitconv
table
[op, e1->type, e2->type]  mapping to bin op allow
for TOK.TOKadd, bool, bool  -> false
    TOK.TOKmul, bool, bool  -> false
    and this naturally fix issue 1511


-- 

January 30, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2172


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com
           Platform|x86                         |All
            Version|1.030                       |D1 & D2
            Summary|bool add bool accepted?     |statically disallow bool +
                   |                            |bool
         OS/Version|Windows                     |All
           Severity|normal                      |enhancement


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 30, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2172


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #4 from bearophile_hugs@eml.cc 2012-01-30 04:28:27 PST ---
The error message looks clear.
And and this point I don't think D boolean semantics will change.
So I think this bug report needs to be closed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 30, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2172


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #5 from yebblies <yebblies@gmail.com> 2012-01-31 02:17:02 EST ---
I tend to agree.

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