From patchwork Thu Jun 23 15:06:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 55332 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11D213856DEC for ; Thu, 23 Jun 2022 15:06:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11D213856DEC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655996810; bh=Sbu10Hqir2+QIVBoYihc+OMF/zWOnlfJlABQ96P1WoU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=nODqN3o67Oy4T5D8x0gn409YitbrXmSTrZft8oe5wpB4geUQp3fgpDMQzM9Gty1FA 6ZPAYuhYPW5COMYXJCB4oz54sNK5d7Fc86h3sCdgj51CXyDcCt+cLccFwAmNPeZbcT dHosdidGFNPAU+sEyodG8j7kWUb2qP2fGv3h8tWA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 BB66838582A3 for ; Thu, 23 Jun 2022 15:06:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BB66838582A3 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-177-JQMvu9KhMHeNnu6-baX9tw-1; Thu, 23 Jun 2022 11:06:17 -0400 X-MC-Unique: JQMvu9KhMHeNnu6-baX9tw-1 Received: by mail-qk1-f198.google.com with SMTP id h22-20020a05620a245600b006ac46bda40eso16601784qkn.18 for ; Thu, 23 Jun 2022 08:06:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Sbu10Hqir2+QIVBoYihc+OMF/zWOnlfJlABQ96P1WoU=; b=gBZhB9eG5f6uat5d8TmQO90aELD1ighttqWhzL1H78LNg8vO7AD+ISqd8TA8MBYpu3 qwdrsevKkJiLjOAjZucAjPNj8Feu13BmlcXjde3NNEts38hdFTrmEbWN7oEsyZ2LOeeC CuZ52B/4hR3tNEseR55W6Pcb6g6880+SDwixI52L8Tc+fhJsKpXNf3RU/6kdMz/bK8gR Mn9s3ILr60zKKNGbhO8FRlES+XyXHqri3vF1AmwsfJgFZy5dNJNenOCFDgtr6VmGeRKz C3HJ0ags4GnIWOBkv2cOcqi/I3un83s+Gmt5e+zBnhdKZp4S0NF0vXbSjQO/XEssHmpq v7/A== X-Gm-Message-State: AJIora/2N0meH2GqElfhyJYo+ocXfpj2YyixUNJ1t3/7E4z/nkIh1vCg 9HGd/KWnHr9Dx6XSJ8Dl1dIohzFjB9aSzNnGW3CJxAjEqJCiwvBU2G1kmGWem6aAmwy15Oo+szc 6Ye76a2NXswrJhEVtiyOvdg1QhrN+c/pHkTvUphHOz1G20LK/wZ/DXQFVajtqlbSzLho= X-Received: by 2002:a05:6214:27cd:b0:46a:a9cb:7aed with SMTP id ge13-20020a05621427cd00b0046aa9cb7aedmr32602917qvb.9.1655996776993; Thu, 23 Jun 2022 08:06:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vjPXs09NAgZ5s+XaCAzd/VNn59xpP0bNingR9MTXBk55Bh6PFHhNsglIS9aq5CNgekSGUOVg== X-Received: by 2002:a05:6214:27cd:b0:46a:a9cb:7aed with SMTP id ge13-20020a05621427cd00b0046aa9cb7aedmr32602832qvb.9.1655996776243; Thu, 23 Jun 2022 08:06:16 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id r67-20020ae9dd46000000b006a5d8d96681sm18051591qkf.100.2022.06.23.08.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jun 2022 08:06:16 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: constexpr folding in unevaluated context [PR105931] Date: Thu, 23 Jun 2022 11:06:04 -0400 Message-Id: <20220623150604.173894-1-ppalka@redhat.com> X-Mailer: git-send-email 2.37.0.rc1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Changing the type of N from int to unsigned in decltype82.C from r12-8472-g47ea22015c90df reveals another spot where we perform constexpr evaluation in an unevaluated context for sake of diagnostics, this time from the call to shorten_compare in cp_build_binary_op, which calls fold_for_warn. We could (and probably should?) suppress the shorten_compare diagnostics when in an unevaluated context, but there's probably other spots that have the same bug. So this patch takes the approach of suppressing fold_for_warn more generally when in an unevaluated context. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/12? PR c++/105931 gcc/cp/ChangeLog: * expr.cc (fold_for_warn): Don't fold when in an unevaluated context. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/decltype82a.C: New test. --- gcc/cp/expr.cc | 5 +++++ gcc/testsuite/g++.dg/cpp0x/decltype82a.C | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/decltype82a.C diff --git a/gcc/cp/expr.cc b/gcc/cp/expr.cc index 31fe0980337..b71245f937d 100644 --- a/gcc/cp/expr.cc +++ b/gcc/cp/expr.cc @@ -397,6 +397,11 @@ fold_for_warn (tree x) { /* C++ implementation. */ + if (cp_unevaluated_operand) + /* In an unevaluated context, we don't care about the reduced value + of an expression, so neither should any warnings. */ + return x; + /* Prevent warning-dependent constexpr evaluation from changing DECL_UID (which breaks -fcompare-debug) and from instantiating templates. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype82a.C b/gcc/testsuite/g++.dg/cpp0x/decltype82a.C new file mode 100644 index 00000000000..cbbcdfd8e58 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/decltype82a.C @@ -0,0 +1,11 @@ +// PR c++/105931 +// { dg-do compile { target c++11 } } +// A version of decltype82.C where N is unsigned. + +template +void f() { + using ty1 = decltype((5 % N) == 0); + using ty2 = decltype((5 / N) == 0); +} + +template void f<0>();