From patchwork Fri Sep 15 16:03:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1835046 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=stsrQqXh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RnJrj1hGcz1yhR for ; Sat, 16 Sep 2023 02:03:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B60523858C2B for ; Fri, 15 Sep 2023 16:03:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B60523858C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694793806; bh=LMv3EnnbcG0Sw0x0fWFmSQ7NlnqqAn+LKIOI5FHcDN0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=stsrQqXhlL/6g/F//ryGqmyV5w3105gFORtyqia4xYhu4thIAJyr+mYMmMNjKyqYC pYnP7nirZUp78z1OMcVhbEzwu+6cK37gSfgPutJVExxQOc7RrLO8U812TYuADVVFWQ u1SDYdNyRza+AOzYEeiCKvwc/NSiEwscWiw01Rek= 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 A6EDA3858C54 for ; Fri, 15 Sep 2023 16:03:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A6EDA3858C54 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-395-g1uC5jUaNJSMvo3Nz7rG3w-1; Fri, 15 Sep 2023 12:03:04 -0400 X-MC-Unique: g1uC5jUaNJSMvo3Nz7rG3w-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-76f2bd12e39so274462285a.2 for ; Fri, 15 Sep 2023 09:03:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694793784; x=1695398584; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LMv3EnnbcG0Sw0x0fWFmSQ7NlnqqAn+LKIOI5FHcDN0=; b=aE5idmdEVxNUBzx5FwvAtP7jWuaZ+cPMATb2zGs7LtPRRHx4VL/Dk8hOK6/K2VqPSg LKULIJ6JWy4VJJTUz1dARMiaFQU/IQEKOxQeiMbZtWefhCb9ASTdLFblTu1c5HITimy/ FYkzmxBLJQflerNOmfJUkX7i6gLQu22r7ao5BbYjBrvZPwj9jCTPm4hAB3or3UlZCvHX lZLaCXdMsZl4DfrYB6Rqv/n3qconFjOa4sJTuoY6hox0CgjJo5uI1E7HR1WEgXMArpBK s7Z9L7Ix36w2QqM2wLsh9hvrrXOX8Udu2HDTF5dg4n/tK+7RlCUdsMIf8b/Fwn3oT5zV mOlQ== X-Gm-Message-State: AOJu0YwLZ2qkzH8R7t0uxu9d0HP7rZAVkUAIp8ITrlu0i2F2Wi02JVYc x2tO9LRO8wr8hsdzpj6Bkgfs4lEr7A0ezu4wQJH6Qeuvt3Tnms9Uaqbt7b8zyYfd8JIX1oea3NA 4VTVRkEG7wE3uAwXHzUnLPJJCyEfu1xZWboMxDxN8bR8eZz/gcH/Av8eksyjwiBEjM75ijKsUPx Q= X-Received: by 2002:a05:620a:a84:b0:76e:f4f1:fa82 with SMTP id v4-20020a05620a0a8400b0076ef4f1fa82mr1816137qkg.41.1694793783686; Fri, 15 Sep 2023 09:03:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVJYC+f1JY0z1VR+9S2xRJNi2GAOuEoWKWjFUFIvhRaaTio3IPnx2lwSVF4yymlOJIffLxnA== X-Received: by 2002:a05:620a:a84:b0:76e:f4f1:fa82 with SMTP id v4-20020a05620a0a8400b0076ef4f1fa82mr1816095qkg.41.1694793783083; Fri, 15 Sep 2023 09:03:03 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id a26-20020a05620a16da00b0076db1caab16sm1325316qkn.22.2023.09.15.09.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 09:03:02 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: overeager type completion in convert_to_void [PR111419] Date: Fri, 15 Sep 2023 12:03:01 -0400 Message-ID: <20230915160301.2245349-1-ppalka@redhat.com> X-Mailer: git-send-email 2.42.0.158.g94e83dcf5b MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Here convert_to_void always completes the type of an INDIRECT_REF or VAR_DECL expression, but according to [expr.context] an lvalue-to-rvalue conversion is applied to a discarded-value expression only if "the expression is a glvalue of volatile-qualified type". This patch restricts convert_to_void's type completion accordingly. PR c++/111419 gcc/cp/ChangeLog: * cvt.cc (convert_to_void) : Only call complete_type if the type is volatile and the INDIRECT_REF isn't an implicit one. : Only call complete_type if the type is volatile. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-requires36.C: New test. * g++.dg/expr/discarded1.C: New test. * g++.dg/expr/discarded1a.C: New test. --- gcc/cp/cvt.cc | 11 +++++++---- gcc/testsuite/g++.dg/cpp2a/concepts-requires36.C | 16 ++++++++++++++++ gcc/testsuite/g++.dg/expr/discarded1.C | 15 +++++++++++++++ gcc/testsuite/g++.dg/expr/discarded1a.C | 16 ++++++++++++++++ 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires36.C create mode 100644 gcc/testsuite/g++.dg/expr/discarded1.C create mode 100644 gcc/testsuite/g++.dg/expr/discarded1a.C diff --git a/gcc/cp/cvt.cc b/gcc/cp/cvt.cc index c6b52f07050..5e2c01476e3 100644 --- a/gcc/cp/cvt.cc +++ b/gcc/cp/cvt.cc @@ -1252,10 +1252,12 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) tree type = TREE_TYPE (expr); int is_reference = TYPE_REF_P (TREE_TYPE (TREE_OPERAND (expr, 0))); int is_volatile = TYPE_VOLATILE (type); - int is_complete = COMPLETE_TYPE_P (complete_type (type)); + if (is_volatile && !is_reference) + complete_type (type); + int is_complete = COMPLETE_TYPE_P (type); /* Can't load the value if we don't know the type. */ - if (is_volatile && !is_complete) + if (is_volatile && !is_reference && !is_complete) { if (complain & tf_warning) switch (implicit) @@ -1412,9 +1414,10 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) { /* External variables might be incomplete. */ tree type = TREE_TYPE (expr); - int is_complete = COMPLETE_TYPE_P (complete_type (type)); - if (TYPE_VOLATILE (type) && !is_complete && (complain & tf_warning)) + if (TYPE_VOLATILE (type) + && !COMPLETE_TYPE_P (complete_type (type)) + && (complain & tf_warning)) switch (implicit) { case ICV_CAST: diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires36.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires36.C new file mode 100644 index 00000000000..8d3a4fcd2aa --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires36.C @@ -0,0 +1,16 @@ +// PR c++/111419 +// { dg-do compile { target c++20 } } + +template +concept invocable = requires(F& f) { f(); }; + +template +concept deref_invocable = requires(F& f) { *f(); }; + +struct Incomplete; + +template +struct Holder { T t; }; + +static_assert(invocable& ()>); +static_assert(deref_invocable* ()>); diff --git a/gcc/testsuite/g++.dg/expr/discarded1.C b/gcc/testsuite/g++.dg/expr/discarded1.C new file mode 100644 index 00000000000..c0c22e9e95b --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/discarded1.C @@ -0,0 +1,15 @@ +// PR c++/111419 + +struct Incomplete; + +template struct Holder { T t; }; // { dg-bogus "incomplete" } + +extern Holder a; +extern Holder& b; +extern Holder* c; + +int main() { + a; + b; + *c; +} diff --git a/gcc/testsuite/g++.dg/expr/discarded1a.C b/gcc/testsuite/g++.dg/expr/discarded1a.C new file mode 100644 index 00000000000..5516ff46fe9 --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/discarded1a.C @@ -0,0 +1,16 @@ +// PR c++/111419 + +struct Incomplete; + +template struct Holder { T t; }; // { dg-error "incomplete" } + +extern volatile Holder a; +extern volatile Holder& b; +extern volatile Holder* c; + +int main() { + a; // { dg-message "required from here" } + b; // { dg-warning "implicit dereference will not access object" } + // { dg-bogus "required from here" "" { target *-*-* } .-1 } + *c; // { dg-message "required from here" } +}