220 28969 <6a135136-1acf-465d-994e-fc3c60fb2764@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: rianquinn@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: uint16_t data =x= static_cast<uint16_t>(1) + 1;
Date: Wed, 19 Oct 2016 05:59:32 -0700 (PDT)
Lines: 146
Approved: news@gmane.org
Message-ID: <6a135136-1acf-465d-994e-fc3c60fb2764@isocpp.org>
References: <47e7f79f-8676-4a63-b7d3-09d64219d575@isocpp.org> <CAFdMc-1RPatYOmggBx=_4uHTMo1hei9npMhXcmyo4VA0muT0gg@mail.gmail.com>
 <15C675BC-1FAC-4196-9978-FAB54B0DE897@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_35_87710164.1476881972850"
X-Trace: blaine.gmane.org 1476881990 16878 195.159.176.226 (19 Oct 2016 12:59:50 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 19 Oct 2016 12:59:50 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDN6PG7E2ALRBOO4TXAAKGQEP64VSIY@isocpp.org Wed Oct 19 14:59:45 2016
Return-path: <std-proposals+bncBDN6PG7E2ALRBOO4TXAAKGQEP64VSIY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-it0-f69.google.com ([209.85.214.69])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDN6PG7E2ALRBOO4TXAAKGQEP64VSIY@isocpp.org>)
	id 1bwqT5-0003AL-HS
	for gclcip-std-proposals@m.gmane.org; Wed, 19 Oct 2016 14:59:39 +0200
Original-Received: by mail-it0-f69.google.com with SMTP id f129sf38913803itc.7
        for <gclcip-std-proposals@m.gmane.org>; Wed, 19 Oct 2016 05:59:42 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=3BvL0/Xb060UmGEq1FxEpQhf76BJ/Mxerw0Iah46tto=;
        b=X5T8lGA9Pxwx9+oUj5huYoQN4hQU2THie/e5RiH2cQ7kfyhUyYV8E4Vz2bi72N6I+y
         uWuGUBBUOn8xOcGi8WIuGht01XFd73qm1ToI5Mob3OsVGOOwugiVA0sS5Ljrd/X6C565
         iPjoEbwRC9rT5eKPye6xyZc7N7X5Z2wXyNu1BJ8ScAAgNRybra0H1yEKHhhQDUArtTZ+
         Sl/HVuh7j3B3YBqsQkYsed3sCUCnkw8BxVl1G57S6ee/wgvtBfSvjv2L2TMl0UgJ0vyi
         yNjLNq2gO1l5U/dydgSWH6Ra0cqWZy2wnDNIf2drLfJWR6AVI3qIdR7K0X4Kt3Q6GwfD
         PbcA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=3BvL0/Xb060UmGEq1FxEpQhf76BJ/Mxerw0Iah46tto=;
        b=RWqrTj37pWZZvPBPeFNOHhG17wKhVCPOnQcGSi+yWpxdyn1u+H7d8k73HYRfo3Q+tC
         4B4SFkRNhyD3Fjtlj2xVBBY5y/1pk8Ukb1/JF6YtNkuY+mDU4BGhOhEo1SaYngtLWBi+
         RcBB8n/7J6DhC/CNOyT55LDzyLEVj5bF3+berGWVyXsmnct7eGIsn6AsbcbuhWjSMeLj
         WTfCH5dseh9YpWgA771quW2Bmwn9Ze2Zn2iO6n20E5YL2zocQVj//plyYpAwALBqwsH4
         eFyJrD10YlQ/bS111lsfNXe57+Kowzdu7S8jANNAbWpOqmny2t/KTJb0WOPGCcfcFAXZ
         0B1A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=3BvL0/Xb060UmGEq1FxEpQhf76BJ/Mxerw0Iah46tto=;
        b=m6r6DMKNkgjoOcv4SUitupd0ZEfxVXeji5DyEMPsYN/YNPECl/Ifn1u6dZqO9Okhr5
         Qdz/HQTwf4nRgR4RQBfPiCvt1VnhyvZcNmGfaQtsHKJIgPtDL/P3PMociVyPGAbPsLDK
         RoGOgnK2Dkf9EAosHMZPmCZ/uGoSl+1/2fILVmXgniBbFW63cUwn5SO9D59mkoIxAkjT
         lzpWet9mM+5G4SzWMHie7oGKB1UajDWixZWyarmF1nA6kh/1lhs+DRabTANXcbcSo6SN
         ZZS+1rWXQTwCmhrwtlcu2gBnlnR+Ryh0cQd+rncSt++OWfq9+aGsVw2X4Fj/jcdCXt3U
         NjVA==
X-Gm-Message-State: AA6/9Rm/ga8DsrXDUk/JInhfZTJH6vKGB/WpaLMcC+drQij9RXOmZ0Bk+H+Le8e/CscX9Q==
X-Received: by 10.107.62.139 with SMTP id l133mr1933694ioa.69.1476881981677;
        Wed, 19 Oct 2016 05:59:41 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.227.79 with SMTP id d76ls3921145ith.4.canary; Wed, 19 Oct
 2016 05:59:34 -0700 (PDT)
X-Received: by 10.36.77.75 with SMTP id l72mr552888itb.1.1476881974113;
        Wed, 19 Oct 2016 05:59:34 -0700 (PDT)
In-Reply-To: <15C675BC-1FAC-4196-9978-FAB54B0DE897@gmail.com>
X-Original-Sender: rianquinn@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:28969
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/28969>

------=_Part_35_87710164.1476881972850
Content-Type: multipart/alternative; 
	boundary="----=_Part_36_1039713435.1476881972850"

------=_Part_36_1039713435.1476881972850
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

These are the flags that we are using:

-Wall -Wextra -Wpedantic -Wctor-dtor-privacy -Wshadow -Wnon-virtual-dtor=20
-Wold-style-cast -Wcast-align -Woverloaded-virtual -Wconversion=20
-Wsign-conversion -DGSL_THROW_ON_CONTRACT_VIOLATION -fpic -fexceptions=20
-fstack-protector-strong -mstackrealign -mmmx -msse -msse2 -msse3 -mssse3=
=20
-msse4.1 -msse4.2 -msse4 -mavx -maes -ffreestanding -mno-red-zone

I think -Wconversion is the offending flag.=20

- Rian



On Wednesday, October 19, 2016 at 6:55:09 AM UTC-6, David Krauss wrote:
>
>
> On 2016=E2=80=9310=E2=80=9319, at 8:31 PM, dgutson . <daniel...@gmail.com=
 <javascript:>>=20
> wrote:
>
>
>
> On Tue, Oct 18, 2016 at 8:11 PM, <rian...@gmail.com <javascript:>> wrote:
>
>> Writing a hypervisor in C++, and at least on Intel that are a lot of=20
>> things that require 8 and 16 bit integers. To my surprise, this generate=
s a=20
>> warning about conversions:
>>
>> uint16_t data1 =3D 1;
>> uint16_t data2 =3D data1 + 1;  // warning on possible overflow
>>
>
> Interestingly, g++ (5.4) does not complain with that snippet, until you d=
o=20
> { } initialization:
>
>
> I tried GCC and Clang with -Wall -Wextra -Woverflow -Wnarrowing and=20
> couldn=E2=80=99t get any diagnoses.
>
> With braces, the narrowing conversion makes the program ill-formed. It is=
=20
> conforming to issue a warning for an ill-formed program, but it is=20
> nonconforming to be quiet. The standard doesn=E2=80=99t usually different=
iate=20
> between error messages and warning messages.
>
> To silence the warning requires a static_cast on the sum: data2{=20
> static_cast< uint16_t >( data1 + 1 ) }.
>
> It would be nice to redo C++ without integer promotion, but perhaps=20
> allowing the same optimization as a matter of undefined overflow, much as=
=20
> floating-point computations don=E2=80=99t have guaranteed imprecision.=20
> Unfortunately, we=E2=80=99re pretty much stuck with it.
>
>

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/6a135136-1acf-465d-994e-fc3c60fb2764%40isocpp.or=
g.

------=_Part_36_1039713435.1476881972850
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">These are the flags that we are using:<div><br></div><div>=
-Wall -Wextra -Wpedantic -Wctor-dtor-privacy -Wshadow -Wnon-virtual-dtor -W=
old-style-cast -Wcast-align -Woverloaded-virtual -Wconversion -Wsign-conver=
sion -DGSL_THROW_ON_CONTRACT_VIOLATION -fpic -fexceptions -fstack-protector=
-strong -mstackrealign -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 =
-msse4 -mavx -maes -ffreestanding -mno-red-zone</div><div><br></div><div>I =
think -Wconversion is the offending flag.=C2=A0</div><div><br></div><div>- =
Rian</div><div><br></div><div><br><br>On Wednesday, October 19, 2016 at 6:5=
5:09 AM UTC-6, David Krauss wrote:<blockquote class=3D"gmail_quote" style=
=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: =
1ex;"><div style=3D"word-wrap:break-word"><br><div><blockquote type=3D"cite=
"><div>On 2016=E2=80=9310=E2=80=9319, at 8:31 PM, dgutson . &lt;<a href=3D"=
javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"wlSLVIzcBgAJ" rel=
=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return true;=
" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">daniel...@gmai=
l.com</a>&gt; wrote:</div><br><div><div dir=3D"ltr"><br><div><br><div class=
=3D"gmail_quote">On Tue, Oct 18, 2016 at 8:11 PM,  <span dir=3D"ltr">&lt;<a=
 href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"wlSLVIzcBg=
AJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;retur=
n true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">rian...=
@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex"><div dir=3D"ltr"><div>Writing a hypervisor in C++, and at least =
on Intel that are a lot of things that require 8 and 16 bit integers. To my=
 surprise, this generates a warning about conversions:</div><div><br></div>=
<div>uint16_t data1 =3D 1;</div><div>uint16_t data2 =3D data1 + 1; =C2=A0//=
 warning on possible overflow<br></div></div></blockquote><div><br></div><d=
iv>Interestingly, g++ (5.4) does not complain with that snippet, until you =
do { } initialization:<br></div></div></div></div></div></blockquote><div><=
br></div><div>I tried GCC and Clang with -Wall -Wextra -Woverflow -Wnarrowi=
ng and couldn=E2=80=99t get any diagnoses.</div><div><br></div><div>With br=
aces, the narrowing conversion makes the program ill-formed. It is conformi=
ng to issue a warning for an ill-formed program, but it is nonconforming to=
 be quiet. The standard doesn=E2=80=99t usually differentiate between error=
 messages and warning messages.</div><div><br></div><div>To silence the war=
ning requires a static_cast on the sum: <font face=3D"Courier">data2{ stati=
c_cast&lt; uint16_t &gt;( data1 + 1 ) }</font>.</div><div><br></div><div>It=
 would be nice to redo C++ without integer promotion, but perhaps allowing =
the same optimization as a matter of undefined overflow, much as floating-p=
oint computations don=E2=80=99t have guaranteed imprecision. Unfortunately,=
 we=E2=80=99re pretty much stuck with it.</div><div><br></div></div></div><=
/blockquote></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/6a135136-1acf-465d-994e-fc3c60fb2764%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6a135136-1acf-465d-994e-fc3c60fb2764=
%40isocpp.org</a>.<br />

------=_Part_36_1039713435.1476881972850--

------=_Part_35_87710164.1476881972850--

.
