220 26480 <57735FA4.8040302@gmx.net> article
Path: news.gmane.org!not-for-mail
From: Jens Maurer <Jens.Maurer@gmx.net>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: if-constexpr short circuiting ambiguity?
Date: Wed, 29 Jun 2016 07:41:56 +0200
Lines: 115
Approved: news@gmane.org
Message-ID: <57735FA4.8040302@gmx.net>
References: <d2934cdf-6a6e-47c7-aa04-660847a8167b@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1467178940 3577 80.91.229.3 (29 Jun 2016 05:42:20 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 29 Jun 2016 05:42:20 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDPMTYGK64JRBK57ZW5QKGQETFDD75I@isocpp.org Wed Jun 29 07:42:12 2016
Return-path: <std-proposals+bncBDPMTYGK64JRBK57ZW5QKGQETFDD75I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f72.google.com ([209.85.215.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDPMTYGK64JRBK57ZW5QKGQETFDD75I@isocpp.org>)
	id 1bI8GH-00007R-Hj
	for gclcip-std-proposals@m.gmane.org; Wed, 29 Jun 2016 07:42:09 +0200
Original-Received: by mail-lf0-f72.google.com with SMTP id l184sf27461542lfl.3
        for <gclcip-std-proposals@m.gmane.org>; Tue, 28 Jun 2016 22:42:09 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=message-id:date:from:user-agent:mime-version:to:subject:references
         :in-reply-to: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=FUeoVhzhxQ6H7zeI5jJgdxSPDL/0Hlcg8sWSX75d4ZI=;
        b=0N3J+h/Qtjsu+oLi5AOCNl2A4DvD1fLbsprtrnhOgX+YA8sdQy39Istu1QyzaGCaG9
         C8kZiThCerkJeAmugHJHKjQS+WU/61riCmEBWoIXt/qqaaIlht/CZ1GRwpmp7/UAqNpo
         PRONsaE4G3IDMLvtvlbPWZmWRS7+NwtcJdBPnFOiIDgMHSpKPIKLvjLOxCVYfnHCe7we
         Is2razc2fg7Q5a7L9aR2chN9VjG/D15JHwmDx5EPqzd+oON68a6IY8RRCj0bIL9m/oC2
         JfD8ZNLPVz4CDyBWCXyyvxfhbOgqrFl9zcfgM+iZPAiHYdxJ4SYIqJ2PWHfWg3VnfdW/
      
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to
         :subject:references:in-reply-to: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=FUeoVhzhxQ6H7zeI5jJgdxSPDL/0Hlcg8sWSX75d4ZI=;
        b=KF7q8J36kdCNu6pZFNG+MH6tLslF4nB4elImfGevZC1zy2MIlMwAi/7vMKMFOUJ6Fi
         axfgtjfGueumhoX7tL3UhVOLwR30X6+KiWH2lIl6bMifzOhaxj18BGl6ErOzu45WHhqd
         wVgzSKy/Bw87+Vz+zivKllNsuT0mcLtXGcs3/tFtoYlE2hhCFIjOMBRL4/e9PM+FfftH
         q48fNQTr4lf0biDhjDYqoyPkzKZTlxQkJnwNRCt1s3u6//p5g9xI6baOGHEmOUXzecr9
         cK0Gio3weGARURhlpBtuKyYjiKNP9Kb1uYQFXM8GrwRXSAsAnV4p/7ogk5RGGLsEWaui
  
X-Gm-Message-State: ALyK8tJ/kBGizqUbAQ45veQSOhWhOcE5/rkbHM2pvm8Irw929oeI8jbghEOOtnkxmInD0Q==
X-Received: by 10.25.163.17 with SMTP id m17mr1311332lfe.1.1467178923928;
        Tue, 28 Jun 2016 22:42:03 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.48.80 with SMTP id w77ls78703wmw.5.canary; Tue, 28 Jun 2016
 22:42:02 -0700 (PDT)
X-Received: by 10.194.141.131 with SMTP id ro3mr6277051wjb.51.1467178922704;
        Tue, 28 Jun 2016 22:42:02 -0700 (PDT)
Original-Received: from mout.gmx.net (mout.gmx.net. [212.227.15.18])
        by mx.google.com with ESMTPS id n10si2898496wjm.77.2016.06.28.22.42.02
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 28 Jun 2016 22:42:02 -0700 (PDT)
Received-SPF: pass (google.com: domain of jens.maurer@gmx.net designates 212.227.15.18 as permitted sender) client-ip=212.227.15.18;
Original-Received: from [192.168.2.100] ([188.101.60.225]) by mail.gmx.com (mrgmx003)
 with ESMTPSA (Nemesis) id 0MaIsi-1b2ejx43UO-00Jtbo for
 <std-proposals@isocpp.org>; Wed, 29 Jun 2016 07:42:02 +0200
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1
In-Reply-To: <d2934cdf-6a6e-47c7-aa04-660847a8167b@isocpp.org>
X-Provags-ID: V03:K0:bHYtku8cp3ahVPLRa1RKHIEfnwvVfQAP+L+Q5fx9O85NNOGAnPR
 xzFdyGZr0Khu9foRg/EuyiHG4S2yOqwV1vzku6QsxheDwyL7sFxB7S2S7fovyBQB+nAhq01
 hWQikJ53YbkXzv3NeFRojrVUQGUZXlfVF6CPKoRmYti8pM/hjRQohHdcyaPw4MDwJHh2iou
 5U6RZ+NBNRgGf7BVWsDHQ==
X-UI-Out-Filterresults: notjunk:1;V01:K0:zPlxam+Pex0=:ZOgKMCKQzgRbvwQ2RD/9YI
 pRbgHyuAd23O7n6++etp1CKM4spPnDgWx9i9xOWxPAA7y2eYM8SVY49xHC6NX+UF+yhhAyUJ9
 Lkr7b0GnI9Z2lJMeTP8WFe/p4k1ttdAmQ73ahiL4krlAmQs6i2MdsG8Z5GltkfYLLLRuO/oXw
 qcywT+4PRk2q2Ir05H0sEOLPE45hhkpvHw4laBQ/tQ1kQ9+5DIeJkI035wS1qa1t68+NfHZMH
 nGHjcd2krpCRMTZYgUWQFTrFkj5g3t1mmnFSidkEuf8Q5PXYLcFMOvUgl7VkHTffC8SaAQv+V
 ZFrerac5arvvCmbJzvG5oxFpJ6v4K+OAImA+oUDJXpwz+6EPi1muznv7Nt8cyQNRrCB5faj0V
 8S2o/+ufpSJGJL4VlopAzZQaD2YMB2O8rqhAvKz1ZhCwHsRoDARoD9FCg3+u876zfhQVRiuZm
 aReOgRsu4KJRUBeG8ApjyB/pdAdCIPt3DQ7QyYKOwPDMKz+D30UgRIHgRYtJuVwiRHmN8nOQy
 /Q8HEbpwQ3w8nhxVykCAKwZJb8fIvioTWNMnWi+jgqRaf8rUFrZtaKjFNfOVansyAZ80jne8T
 BLi4AyuK+ExH69XATL01I015aG55rI+e94GNssetgDmJmJQCaTgf6/L7Bg4FxXEdaK3C5NpPX
 2V1k0WnMzm1TAtb8gyEchwga6rSddIaOaEgGMz2+NHhJpHInZbNldG4YTMG7YAXiuyul6suaD
 ZpOsD96QhkVK41BkQQAisL1280yosoU7cXQjTxbTjEXqC4GSEFQdW3qUDzSp+jW+ZfQ1BY8z 
X-Original-Sender: Jens.Maurer@gmx.net
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of jens.maurer@gmx.net designates 212.227.15.18 as permitted sender) smtp.mailfrom=Jens.Maurer@gmx.net
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:26480
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/26480>


The condition for the if-constexpr is instantiated as a whole,
and needs to be valid.  You can nest the if-constexpr, though:

if constexpr (std::is_same_v<MyType, T>)
  if constexpr (T::i =3D=3D 5)   // not instantiated if outer condition is =
false
    ...

Jens


On 06/29/2016 06:33 AM, lefticus@gmail.com wrote:
> Forgive me if this has already been answered or I'm posting to the wrong =
forum.
>=20
> I was just reading the if-constexpr proposal that was accepted in Oulu (h=
ttp://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0292r1.html, I beli=
eve) and trying out the implementation that's currently on clang's trunk. I=
 believe there is an unresolved question about short circuiting.
>=20
> Example:
>=20
> ||
> #include <iostream>
> #include <type_traits>
>=20
> struct MyType
> {
>   static const int i =3D 5;
> };
>=20
> template<typename T>
> void do_thing(const T &t)
> {
>   if constexpr (std::is_same_v<MyType, T> && T::i =3D=3D 5) {
>     std::cout << "MyType::i =3D=3D 5\n";
>   } else {
>     std::cout << "don't know...\n";
>   }
> }
>=20
> int main()
> {
>   do_thing(MyType());
>   do_thing(3); // fails to compile because of the T::i expression in the =
if-constexpr above
> }
>=20
>=20
> This code fails to compile in the current implementation of if-constexpr =
in clang.
>=20
> However, the equivalent code:
>=20
> ||
> #include<type_traits>
>=20
>=20
> structMyType
> {
>   staticconstinti =3D5;
> };
>=20
> template<typenameT>
>   autodo_thing(constT &t)->std::enable_if_t<std::is_same<MyType,T>::value=
 &&T::i =3D=3D5>
> {
> }
>=20
> template<typenameT>
>   autodo_thing(constT &t)->std::enable_if_t<!std::is_same<MyType,T>::valu=
e>
> {
> }
>=20
> intmain()
> {
>   do_thing(MyType());
>   do_thing(3);
> }
>=20
>=20
> Succeeds to compile.
>=20
> It would be my opinion that the if-constexpr conditional *should* short-c=
ircuit at compile time, but I don't see if the accepted proposal specifies =
one way or the other.
>=20
> Thank you,
> Jason
>=20
> --=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=
 email to std-proposals+unsubscribe@isocpp.org <mailto:std-proposals+unsubs=
cribe@isocpp.org>.
> To post to this group, send email to std-proposals@isocpp.org <mailto:std=
-proposals@isocpp.org>.
> To view this discussion on the web visit https://groups.google.com/a/isoc=
pp.org/d/msgid/std-proposals/d2934cdf-6a6e-47c7-aa04-660847a8167b%40isocpp.=
org <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d2934cdf-=
6a6e-47c7-aa04-660847a8167b%40isocpp.org?utm_medium=3Demail&utm_source=3Dfo=
oter>.

--=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/57735FA4.8040302%40gmx.net.

.
