From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 91A633858435 for ; Fri, 26 Nov 2021 12:43:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 91A633858435 Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-13-6MbAfn-SN0-igTBooAHQrw-1; Fri, 26 Nov 2021 07:43:55 -0500 X-MC-Unique: 6MbAfn-SN0-igTBooAHQrw-1 Received: by mail-yb1-f200.google.com with SMTP id g36-20020a25ae64000000b005c1f46f7ee6so10521518ybe.8 for ; Fri, 26 Nov 2021 04:43:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/gG3HEJXvyTnJnD/BfIlGnU9BxKsiFWBrdspcgPnNZw=; b=FT4sQtFMsdGqq34rlOWcDYVzbKTxNpKMYdslPOfdZeHYj7pdrDkVMm1pXpv+72F72w tnzcZKicduQxr5bUKEOK3fkJ3S5albKBcMaF0ONJ16o8ZVR0/hLwYu9m7ZDwbx0FSSrX 60OIUOgXxoXwNZusIy3R6an6YtaTyhhvgEy5w6GHflE23ZH0djY12m8A1g6ufxLvPZ5B aiIvJDc0i4TRju3DIQw4quglViejmzW0NHI18lkWgju/k4h02nOK1o2lbYfo/ybKNDZS ZophZ693mcTP42l3Xo5oHrOzeq88LmY7avuLHy2bEU5UXuo/6VEQbxe03LkxuBO4yBOi 4O2w== X-Gm-Message-State: AOAM532fnaQ1LNef8oxKH/agwnLDz3dXVJMVMwk5ZmAGQEfAGNHZs/HY E34tTrMHLSOfQAPntnSNFp3rV0VMRC0vWgZ8UhOllyK27VwmMRnNvFlPgnVsjq5odY1qCgAr+zT LCW0cn/n+cp9sVIai0Ihz4FQ3ZSu5qEU= X-Received: by 2002:a25:25d2:: with SMTP id l201mr15015647ybl.136.1637930635431; Fri, 26 Nov 2021 04:43:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwr/zpPC4dlUy41YlxkBHZWDqny9WdhOrULxizFrmPOGJnmxG5fLlXFZtBoiWnj0HjDeTPekYBpiy+4cQYRQVQ= X-Received: by 2002:a25:25d2:: with SMTP id l201mr15015627ybl.136.1637930635232; Fri, 26 Nov 2021 04:43:55 -0800 (PST) MIME-Version: 1.0 References: <20211126122925.1626170-1-jwakely@redhat.com> <20211126123950.GG2646553@tucnak> In-Reply-To: <20211126123950.GG2646553@tucnak> From: Jonathan Wakely Date: Fri, 26 Nov 2021 12:43:44 +0000 Message-ID: Subject: Re: [PATCH] libstdc++: Define std::__is_constant_evaluated() for internal use To: Jakub Jelinek Cc: "libstdc++" , gcc Patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2021 12:43:59 -0000 On Fri, 26 Nov 2021 at 12:39, Jakub Jelinek wrote: > > On Fri, Nov 26, 2021 at 12:29:25PM +0000, Jonathan Wakely via Gcc-patches wrote: > > + // Internal version of std::is_constant_evaluated() for C++11. > > + // This can be used without checking if the compiler supports the built-in. > > + constexpr inline bool > > + __is_constant_evaluated() noexcept > > + { > > When you have such a nice one spot, shouldn't it: > #if __cpp_if_consteval >= 202106L > if consteval > { > return true; > } > else > { > return false; > } > #elif __has_builtin(__builtin_is_constant_evaluated) > ... > > Theoretically not all compilers need to support the builtin and in C++23 > mode if consteval should be slightly more efficient. Yes, good idea. We actually still have two spots, because we still have std::is_constant_evaluated as well, which is only defined if it actually works. But we can use the same implementation in there (or make it call std::__is_constant_evaluated()). I'll prepare a new patch soon. > One disadvantage of std::__is_constant_evaluated() is that Marek's > warning for if constexpr (std::is_constant_evaluated()) will not trigger > if __is_constant_evaluated() is used instead. But I'd hope testsuite > coverage would discover it quickly if such bug would appear... Yes, and I hope I won't make that mistake anyway, or miss it in reviews. It's a good warning for users, but I like to think I don't need it (and now we start the sweepstake on how many days until I push a patch making exactly that mistake ;-)