C++ Logo

std-proposals

Advanced search

Re: Prevent Assignments from contextually converting to bool

From: Tjernstrom, Staffan <Staffan.Tjernstrom_at_[hidden]>
Date: Wed, 23 Oct 2019 17:11:30 +0000
" Code that intends to do this can simply put parenthesis around the assignment or use an init-statement,"

This would break compatibility with a lot of existing code, especially of the C-compatible forms

if ( num_read = read( buff, count, 1, fd ) )
{
   handle_buffer( buff, num_read );
}

-----Original Message-----
From: Std-Proposals [mailto:std-proposals-bounces_at_[hidden]] On Behalf Of std-proposals-request_at_[hidden]
Sent: Wednesday, 23 October, 2019 13:00
To: std-proposals_at_[hidden]
Subject: Std-Proposals Digest, Vol 7, Issue 40

Send Std-Proposals mailing list submissions to
std-proposals_at_[hidden]

To subscribe or unsubscribe via the World Wide Web, visit
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
or, via email, send a message with subject or body 'help' to
std-proposals-request_at_[hidden]

You can reach the person managing the list at
std-proposals-owner_at_[hidden]

When replying, please edit your Subject line so it is more specific than "Re: Contents of Std-Proposals digest..."


Today's Topics:

   1. Re: Reply to Herb Sutter about Zero-Overhead deterministic.
      It is not true. (Ville Voutilainen)
   2. Re: Reply to Herb Sutter about Zero-Overhead deterministic.
      It is not true. (Arthur O'Dwyer)
   3. Re: Reply to Herb Sutter about Zero-Overhead deterministic.
      It is not true. (Ville Voutilainen)
   4. Prevent Assignments from contextually converting to bool
      (connor horman)
   5. Re: Prevent Assignments from contextually converting to bool
      (Brian Bi)


----------------------------------------------------------------------

Message: 1
Date: Wed, 23 Oct 2019 17:50:24 +0300
From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
To: sotrdg sotrdg via Std-Proposals <std-proposals_at_[hidden]>
Cc: "Arthur O'Dwyer" <arthur.j.odwyer_at_[hidden]>, sotrdg sotrdg
<euloanty_at_[hidden]>
Subject: Re: [std-proposals] Reply to Herb Sutter about Zero-Overhead
deterministic. It is not true.
Message-ID:
<CAFk2RUaLrzgVkbmV2T2j8RCrU_7jeLP-jBbrKO3PQPFFK9f+kA_at_[hidden]>
Content-Type: text/plain; charset="UTF-8"

On Wed, 23 Oct 2019 at 17:38, Arthur O'Dwyer via Std-Proposals <std-proposals_at_[hidden]> wrote:
> (Furthermore, I think that C++2a [and C++2b] should be delayed.)

That record you're playing is broken.


------------------------------

Message: 2
Date: Wed, 23 Oct 2019 12:04:01 -0400
From: "Arthur O'Dwyer" <arthur.j.odwyer_at_[hidden]>
To: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Cc: sotrdg sotrdg via Std-Proposals <std-proposals_at_[hidden]>
Subject: Re: [std-proposals] Reply to Herb Sutter about Zero-Overhead
deterministic. It is not true.
Message-ID:
<CADvuK0Jgi39sU+Rfwf8v1mZpRPgT0w_je95EpRcb4_L=SzyCiQ_at_[hidden]>
Content-Type: text/plain; charset="utf-8"

On Wed, Oct 23, 2019 at 10:50 AM Ville Voutilainen < ville.voutilainen_at_[hidden]> wrote:

> On Wed, 23 Oct 2019 at 17:38, Arthur O'Dwyer via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> > (Furthermore, I think that C++2a [and C++2b] should be delayed.)
>
> That record you're playing is broken.
>

Not as broken as C++2a. ;)

?Arthur
-------------- next part --------------
HTML attachment scrubbed and removed

------------------------------

Message: 3
Date: Wed, 23 Oct 2019 19:13:41 +0300
From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
To: "Arthur O'Dwyer" <arthur.j.odwyer_at_[hidden]>
Cc: sotrdg sotrdg via Std-Proposals <std-proposals_at_[hidden]>
Subject: Re: [std-proposals] Reply to Herb Sutter about Zero-Overhead
deterministic. It is not true.
Message-ID:
<CAFk2RUbS22twr_2bx9uvDZ1va3xjXWvtBTEzmL_E76oNDRcYvg_at_[hidden]>
Content-Type: text/plain; charset="UTF-8"

On Wed, 23 Oct 2019 at 19:04, Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]> wrote:
>
> On Wed, Oct 23, 2019 at 10:50 AM Ville Voutilainen <ville.voutilainen_at_[hidden]> wrote:
>>
>> On Wed, 23 Oct 2019 at 17:38, Arthur O'Dwyer via Std-Proposals
>> <std-proposals_at_[hidden]> wrote:
>> > (Furthermore, I think that C++2a [and C++2b] should be delayed.)
>>
>> That record you're playing is broken.
>
>
> Not as broken as C++2a. ;)

That's almost as funny as other kinds of trolls on the internet, i.e. not very.


------------------------------

Message: 4
Date: Wed, 23 Oct 2019 12:35:18 -0400
From: connor horman <chorman64_at_[hidden]>
To: std-proposals_at_[hidden]
Subject: [std-proposals] Prevent Assignments from contextually
converting to bool
Message-ID:
<CADLV35iaJ98ym2Xs-qXncsNFws1Ek4FH8NhKq9ToetuMKiy88g_at_[hidden]>
Content-Type: text/plain; charset="utf-8"

This is my proposed to solution to one of the worst logic errors in any number of languages, being:
if(i=0)
vs.
if(i==0)

The proposal is to tweak the wording of contextual conversions to bool, prohibiting unparenthesised assignments from being eligible for contextual conversion. Code that intends to do this can simply put parenthesis around the assignment or use an init-statement, and code that does this without intention (i.e. intends the comparison) would be elevated from a logic error (the worst kind honestly) to a compile-time error.
-------------- next part --------------
HTML attachment scrubbed and removed

------------------------------

Message: 5
Date: Wed, 23 Oct 2019 11:43:45 -0500
From: Brian Bi <bbi5291_at_[hidden]>
To: std-proposals_at_[hidden]
Subject: Re: [std-proposals] Prevent Assignments from contextually
converting to bool
Message-ID:
<CAMmfjbOsk0K40UDzmermppiDCatDrePeQd1LCbisiOEfWyXC1A_at_[hidden]>
Content-Type: text/plain; charset="utf-8"

On Wed, Oct 23, 2019 at 11:35 AM connor horman via Std-Proposals < std-proposals_at_[hidden]> wrote:

> This is my proposed to solution to one of the worst logic errors in
> any number of languages, being:
> if(i=0)
> vs.
> if(i==0)
>
> The proposal is to tweak the wording of contextual conversions to
> bool, prohibiting unparenthesised assignments from being eligible for
> contextual conversion. Code that intends to do this can simply put
> parenthesis around the assignment or use an init-statement, and code
> that does this without intention (i.e. intends the comparison) would
> be elevated from a logic error (the worst kind honestly) to a compile-time error.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

You can achieve this effect using compiler warnings. For example, with GCC and Clang, you can use the flag -Werror=parentheses to treat this as an error.

I do not think we should add more rules to the language that discriminate among expressions on the basis of properties other than their type and value category.

--
*Brian Bi*
-------------- next part --------------
HTML attachment scrubbed and removed
------------------------------
Subject: Digest Footer
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
------------------------------
End of Std-Proposals Digest, Vol 7, Issue 40
********************************************
________________________________
IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Received on 2019-10-23 12:13:46