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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 8CAF4385840B for ; Tue, 5 Oct 2021 17:05:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8CAF4385840B Received: from mail-vs1-f70.google.com (mail-vs1-f70.google.com [209.85.217.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-337-MzT0JM3CPxeuu8jfRZk_sg-1; Tue, 05 Oct 2021 13:05:32 -0400 X-MC-Unique: MzT0JM3CPxeuu8jfRZk_sg-1 Received: by mail-vs1-f70.google.com with SMTP id p7-20020a056102274700b002d863e54bcaso1077225vsu.14 for ; Tue, 05 Oct 2021 10:05:31 -0700 (PDT) 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:content-transfer-encoding; bh=VCt8u1fNmAPGJGfRHPceGGutFjFJz5Fsm1VHo5BTeNM=; b=huIOo3OboOILJt9SbI7VOyI52OT/G7n91ILB36RrzSPycrUpCwfdSVuGJH0cY/CE0G h2+JSw5JsiwLIKxheuqH9L7CEL/otHdBuxk0vCjXuysz0gHoLmoXLyCPP+RB3AQYcJfh AgPTjVnjY/Esvo+CllpfhbznUqJpDe/NR4Uklp5ojI+ffz6DSyeE/HMCF938jYPixuwN HqZQCfuueREl4BR993epcKHxpVRh+YFoGk1Vr38pa+bjHNZmzxmuAb+sD209Ilzi30XI W9Os5y10h29I+6JYbZAQd9DG+5PfP+h56Lsn1uSK4Zx/42Ubw+FMuVtaZAD03lCZ/CZd X10w== X-Gm-Message-State: AOAM530wEBocSkBfjpcBnJ11lw0tH/1ppjJhwll1pqsPXUROzwrcwD5q Mv1g2Xm5Kfjm1qYxZujPeE+tp3m090qI71TrmfV0uOzc4lbYwtxtQ6jDmQ61Z2bvXOM/kugA+DK h++c2HxfjDmRT+kXMCX2tMNC+aH8wfCU= X-Received: by 2002:ab0:7e85:: with SMTP id j5mr13208784uax.2.1633453531538; Tue, 05 Oct 2021 10:05:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCYIXJiGcxCHuQmdrvyx/dJ9hE++iX3UVFBf/BImurZSpAfuXwhoaK/X6NLCFjApMcLvU1nE1xyaIrqyvSpyE= X-Received: by 2002:ab0:7e85:: with SMTP id j5mr13208765uax.2.1633453531353; Tue, 05 Oct 2021 10:05:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Tue, 5 Oct 2021 18:05:20 +0100 Message-ID: Subject: Re: An interesting thought on exception_defines.h just for fun To: unlvsur unlvsur Cc: "unlvsur unlvsur via Libstdc++" X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-6.1 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham 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: Tue, 05 Oct 2021 17:05:36 -0000 On Tue, 5 Oct 2021 at 17:57, unlvsur unlvsur via Libstdc++ wrote: > > Is that possible to use if constexpr(true) for __try and if constexpr(fal= se) for __catch when we compile it with C++17 and C++20 instead of If(true)= and if(false) when people disable exceptions? > > gcc/exception_defines.h at 16e2427f50c208dfe07d07f18009969502c25dc8 =C2= =B7 gcc-mirror/gcc =C2=B7 GitHub Yes, that should work OK, but I don't expect it to make much difference in practice. It might prevent some template instantiations if something is only odr-used in a catch handler, but that wouldn't be very common, and those instantiations would be discarded by the compiler anyway, because the if (false) branch is never taken. --- a/libstdc++-v3/libsupc++/exception_defines.h +++ b/libstdc++-v3/libsupc++/exception_defines.h @@ -32,8 +32,13 @@ #if ! __cpp_exceptions // Iff -fno-exceptions, transform error handling code to work without it. -# define __try if (true) -# define __catch(X) if (false) +# if __cplusplus >=3D 201703L +# define __try if constexpr (true) +# define __catch(X) if constexpr (false) +# else +# define __try if (true) +# define __catch(X) if (false) +# endif # define __throw_exception_again #else // Else proceed normally.