220 38052 <0918afa6-6f04-fdc1-fd80-f2843a5e63f1@gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Andrey Semashev <andrey.semashev@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: [[likely]] attribute for switch case
Date: Tue, 8 May 2018 19:08:44 +0300
Lines: 53
Approved: news@gmane.org
Message-ID: <0918afa6-6f04-fdc1-fd80-f2843a5e63f1@gmail.com>
References: <9adde2c8-8306-4708-96f2-edb621d906c7@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Trace: blaine.gmane.org 1525795603 13906 195.159.176.226 (8 May 2018 16:06:43 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 8 May 2018 16:06:43 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
 Thunderbird/52.7.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCXY5TXHWYJRBD4XY7LQKGQEKNBCESA@isocpp.org Tue May 08 18:06:38 2018
Return-path: <std-proposals+bncBCXY5TXHWYJRBD4XY7LQKGQEKNBCESA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f70.google.com ([209.85.215.70])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCXY5TXHWYJRBD4XY7LQKGQEKNBCESA@isocpp.org>)
	id 1fG58P-0003Ut-AF
	for gclcip-std-proposals@m.gmane.org; Tue, 08 May 2018 18:06:37 +0200
Original-Received: by mail-lf0-f70.google.com with SMTP id o16-v6sf2490521lff.13
        for <gclcip-std-proposals@m.gmane.org>; Tue, 08 May 2018 09:08:48 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1525795728; cv=pass;
        d=google.com; s=arc-20160816;
        b=NckSN29K28y8d56b59Y5W0GP4HfG9Ml2r9SyrPrexBMLxEZr/AmILFOrzn734l9Aj4
         jDWHnQDFEENSkxc6Ws5s9yJVJQM3fecimOtfQe+CU72UC5A0Gzzdm7UgMXdeY4kSzFFX
         c7Vq188XoB74ajpKpd6yYUxJf0iWDKPjS68wrxYVnRkLllxWcSY1oK++rbvOVBDf9JG0
         rPvbjHYT7A1zEQkLCIMlevuVTU+3vViTyWBleZrY62B8Ex+5GKjcLCAqq/JxpMFjtl9N
         zLt1Pw8lWOKd4s3w90AKWKLVW8cRh37eLbf00GE7SrgzPlmdU2K4HUjm7wdtsgTOE5AT
         QowQ==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:content-transfer-encoding
         :content-language:in-reply-to:mime-version:user-agent:date
         :message-id:from:references:to:subject:arc-authentication-results
         :arc-message-signature:dkim-signature:arc-authentication-results;
        bh=jOScOLt5BxITI5xyX+Ou+DGS9mDHlOMzKNpq7jS09NQ=;
        b=uzYUmQhdi91r0OKfHAoMWpuQy2RfzKa6d+ckkcnG/xrC7HNt5FzMc6d4RxqaKLjZTB
         VmKMGypEC8TmaZbEs10VGbwz8sQOSEDNqCIENhFzfPnHSv2ke9/jFZu293OggyCa7Ia1
         cVOdHIf7607ogkNpX8qnXwc479Df1Wn2ZSu84wsvg1n5HcqNr2KN+yH0B0WaINs/nsAv
         aSe8H6okBwmGwkF78+jnIufL0VpXF02hp3wFi2JBmYe+8pdW1fUrNMOkkCeSCqluvJD9
         SsqrOUk/5vyETlQWxpcFFDvxlx9MeVV4HL1KcTlNmlsOolPmeENwuCIx2qoYFw 
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=gKYMBzWQ;
       spf=pass (google.com: domain of andrey.semashev@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=andrey.semashev@gmail.com;
       dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=subject:to:references:from:message-id:date:user-agent:mime-version
         :in-reply-to:content-language:content-transfer-encoding
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=jOScOLt5BxITI5xyX+Ou+DGS9mDHlOMzKNpq7jS09NQ=;
        b=c3QJEUQssVTPnehS5BZid6D+ciWE978Li0IgVgYXf0T+UvB0haGNeGKFOLvpU2LalE
         b33NREq29u95/HjLAXQLV9gHyO1h0v2JJYLOle8VEvvxm90ICuEt7hQyKTdWeUOQPp5I
         RUAXcgKup0BFbuDoFWU2ifjcPivRCG31sWLyTLAFML7vpBop2c9B891v6XNMhW2YfF9C
         KRIV95Ef44lLpXtNon0MErYNS2gqylkegFvSMVmlQ2dbqqQr4usQxaRARSqKu/0nfvV4
         BYoW/XA3wiFUYaeGw95nqgn2Z7VD/fh2dE3PCa6kZwPt7F2jm/2bWIL5lCQSVSXF3lZB
         NZJ 
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:references:from:message-id:date
         :user-agent:mime-version:in-reply-to:content-language
         :content-transfer-encoding:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=jOScOLt5BxITI5xyX+Ou+DGS9mDHlOMzKNpq7jS09NQ=;
        b=IqD5xgtykMNXyKQMP3CX+tZZUV8NP7KHCgarEusREn7Pjws5BO+RspkBFRhXCrW+gZ
         pqLVArSDMzmmxuPpn6ce7WwoF8Os+4YbFE9Ffpk2MM7aOQwIkMsvB+4ncdCbtSUGs0A0
         S4mbZzjFOZyD7gQVVtX+VNS5YkKGXsGfn1vUB/T9DztlHjDMTjkPRlWszZmigH//29cJ
         gN5G3f/z56LyYYmfCuH56elkhPS4D/qBEVvi1inglRcq+G5sw2akiUtdMbqi4nx9Z29j
         851r/tQiwSvXgcmsxTzd12JIyFVK/DnoHP30r5SC5nj 
X-Gm-Message-State: ALKqPwc2F4D7fvjNZGwHQQtAO1QQ7HvXk9U7egZoswpS4VK3MOOgx9Lq
	Nork5oiCZnaMpdEKCUYH3DLq1g==
X-Google-Smtp-Source: AB8JxZqefC7X/kDE/wgOOazRbYq6S6h9AOzKEmLVqDswM4CH+Wfu9yOL4gvhmY6jGfc9x5lypQGLNw==
X-Received: by 2002:a19:d7d8:: with SMTP id q85-v6mr680943lfi.24.1525795728557;
        Tue, 08 May 2018 09:08:48 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a2e:868c:: with SMTP id l12-v6ls207044lji.4.gmail; Tue, 08
 May 2018 09:08:47 -0700 (PDT)
X-Received: by 2002:a2e:9a50:: with SMTP id k16-v6mr27489123ljj.36.1525795727042;
        Tue, 08 May 2018 09:08:47 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1525795727; cv=none;
        d=google.com; s=arc-20160816;
        b=fdMt/JJ3mclpPOJn3PHbVL16odN8DtwkuNgY+U2IKsUkVTxiKu0V/95HlzvbINIR+E
         +yoBAo7L8mmSYMrjuxr1Gq52uuVvItyRRj/TXbZfZwO9dg5LqrTPvwPgIb1KaujCIfXv
         eWCrF+os/uGyFyZc4fQJ44/t1i4213yPGWCtxYye09Zn0e/TNjEroxfhbn3uW+APklS3
         ujBNsEqmgogjOrVDLklUyrcmIJzxC/CcGUotf7ePNhLZRDO4NkyDt0e7jf+0aFIbOIXT
         Nx9/HQk39thMtCpbUvEqt7Rs+Jnho0PtwpOourLKCnN9b5s7EaOLb2aHYLQerfXiAc0+
         YCgA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-transfer-encoding:content-language:in-reply-to:mime-version
         :user-agent:date:message-id:from:references:to:subject
         :dkim-signature:arc-authentication-results;
        bh=MeVbdnEMvQ5MqrlxdXaG1R36WIMQlfxKV+y2Cfi/Y8U=;
        b=Tt63kOYR+qg1+TvVOtGC+Wt5s5Crd39thN7tIWW93wr5tKWiXkKQhRx89qNDeMAc2O
         BnWiPAD39NnTU4x9KKdkPhKFZwM81WrUUbUEoyU6WCiUf7RBHn2I7+Z9iK2JEPbJSJt8
         n9eHpizMjnoXmmqY/e3LiFJQFV2BOdR+TNQ1/bbw49hNzWvkAG0AoRV9JSnFfJ7F2f52
         ed/dmHA6jVYsq9bkZnAzhMKYGnqcqSkpUDtn5lspLqpZTdOwNd6rB1chVzrEzMgiSdDb
         4bjPK3s9H5455q91M6wQY2UZGNUxtih+RJx/Iw5fxZE/Tiz6RbeDfYLPx5MuZGeZmzgd
         Lb+g==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=gKYMBzWQ;
       spf=pass (google.com: domain of andrey.semashev@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=andrey.semashev@gmail.com;
       dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
Original-Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41])
        by mx.google.com with SMTPS id j13-v6sor4663283ljg.110.2018.05.08.09.08.47
        for <std-proposals@isocpp.org>
        (Google Transport Security);
        Tue, 08 May 2018 09:08:47 -0700 (PDT)
Received-SPF: pass (google.com: domain of andrey.semashev@gmail.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41;
X-Received: by 2002:a2e:9616:: with SMTP id v22-v6mr27756843ljh.130.1525795726393;
        Tue, 08 May 2018 09:08:46 -0700 (PDT)
Original-Received: from [192.168.1.2] (broadband-109-173-28-102.ip.moscow.rt.ru. [109.173.28.102])
        by smtp.googlemail.com with ESMTPSA id t19-v6sm3702412ljj.46.2018.05.08.09.08.45
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 08 May 2018 09:08:45 -0700 (PDT)
In-Reply-To: <9adde2c8-8306-4708-96f2-edb621d906c7@isocpp.org>
Content-Language: en-US
X-Original-Sender: andrey.semashev@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.s=20161025 header.b=gKYMBzWQ;       spf=pass
 (google.com: domain of andrey.semashev@gmail.com designates 209.85.220.41 as
 permitted sender) smtp.mailfrom=andrey.semashev@gmail.com;       dmarc=pass
 (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: 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:38052
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/38052>

On 05/08/18 18:48, david.bolvansky@gmail.com wrote:
> Hello,
>=20
> Since in C++20 we can write:
>=20
> char * b(int e) {
> if=C2=A0 ([[likely]] e =3D=3D 0)
> return "0";
> else if (e =3D=3D 1)
> return "1";
>  =C2=A0 =C2=A0else return "undef";
> }
>=20
> Can likely attribute be added even for switch case? Like for example:
>=20
> switch(e) {
>  =C2=A0 =C2=A0 case 0 [[likely]]:
>  =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return "0";
>  =C2=A0 =C2=A0 case 1:
>  =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return "1";
>  =C2=A0 =C2=A0 default:
>  =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return "undef";
>=20
> }
>=20
>=20
> I read the "likely" attribute=20
> proposal=C2=A0http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p04=
79r0.html=20
> and they do not mention this use case for switches.

N4741 includes and example with `switch`/`case` in [dcl.attr.likelihood]/3.

I suspect your example with an `if` statement is not doing what you=20
think it does. The [[likely]] applies to the condition expression, which=20
basically says "this condition is likely to be executed" and not "this=20
condition is likely to be true". The correct example is also given in=20
the aforementioned section.

This is the most unfortunate aspect of this proposal as it makes it=20
incompatible with __builtin_expect and tons of code that wraps it in macros=
..

--=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/0918afa6-6f04-fdc1-fd80-f2843a5e63f1%40gmail.com=
..

.
