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 3C8693858C54 for ; Tue, 28 Nov 2023 16:51:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C8693858C54 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3C8693858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701190281; cv=none; b=or/fqnfM+Qzja7l1vDzwQ8mSLPnyChKupHdmIF9Augmn7Nf+d+kdzU62D4drL/f+VXkDrUlExJaOOOazokN82L//8I/FPNK8k4ET4PJaMW6mm12fKFMQE+QNQTS7lPbkKCCVMCeh4NxJ/9HDhdPE0UnLCnB4daBsQvZm+DHUQro= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701190281; c=relaxed/simple; bh=W54Inro6d3qBI9JRrPp/6RZ2Xk2JSkuT1kVx/0AGuoA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rW928A+0+uyEPzcEqXrp6cjOJ9ICP3pTY5IyPWbexRlLNy3fYvekt4AmAigqEJ8ENHbs0dnjPDMpLjE7pcYmKZfg5goTjQ9V+8UEPaN7IKGlVR2/1z9/RGfUUAkX8RBQnBiSkuR6PE+dyqIWfIo9e0EJYvH1Jg52f4cZd7i3YH8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701190279; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hFFBZ+JRsGFJGT52WwmFlyWJE4wlTXFVg7ooGCHMxAA=; b=dKkqM+w8Hx90LkxltQK2h0BEoMsW1DeUvDQC/m1D3UrpOV0i1QDmMsWYoDDl2tff12L2yX ZD10oZwlgD3dmdOUYLLOfZzLCvBWYYaMFXEAAWK6B7lL76vHdRowg5lRksfiMPYDaaQpep +LWhhJuCxw4UtbJpaXKKzXg3JHp/W/k= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-91-w51TEQa_Mz2-hsb2M4V_Jw-1; Tue, 28 Nov 2023 11:51:18 -0500 X-MC-Unique: w51TEQa_Mz2-hsb2M4V_Jw-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-67a6277eab6so4695716d6.1 for ; Tue, 28 Nov 2023 08:51:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701190276; x=1701795076; 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=hFFBZ+JRsGFJGT52WwmFlyWJE4wlTXFVg7ooGCHMxAA=; b=LW2yXO9kS6hFPVoXakawsBivQzbODOywcBmrpH9Ep9W41bajGPWO3+2UWqZIv2eZsV 8eZ27QejO0H/FQxz2TnICmNVoDoJkjFLn98v1vthcNKyKVOJcXiYZ1ziioa4S1cSkQ3d CDeDYPx0gfT4X+OLyuAioWk7fjhUWDGZAE4HyshI+tgUY/1SLsHgGRDCKt5zpchj6qfO 3WPgKqIRk0zoHv260GZCCJD0C1vDf0v5mh8jwLVJRlpasN6knHHDHs9eRas8fEuVmyRB CUZqgmJ3Gxr8TPTkBbT0K2Np0uoJAjIr2WXAr3i3XW0x+TFxGo0yOgEiqG6uwuFXvebb oUpA== X-Gm-Message-State: AOJu0YxnnyH/th3jv5zaGNrAnT5tvSOZ1C/z9Q4dJL+QpT7BGMQ9KrXb cabbo9S9JZF6f3wHYc2sWbfIRgG68wTrDvPyUfqzpZwAa15HNTnErC1NboyQSl+wcglcgZ8j4IU MK0kWZJjAVRhC5tD1GuBttXtxYEtCKuD4nfu33ThUlJdcHy6yaK8uWSDdGQ+Mknw7dKt8TGw9N7 E= X-Received: by 2002:a0c:ead0:0:b0:67a:15dd:a99f with SMTP id y16-20020a0cead0000000b0067a15dda99fmr17336380qvp.46.1701190276136; Tue, 28 Nov 2023 08:51:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8Rlry7phkwakl/gnz9BUKzgpd/qkMcjYx52cUwF80fF0SA9owBUlrw/8HSbAgXz+m3pI3bQ== X-Received: by 2002:a0c:ead0:0:b0:67a:15dd:a99f with SMTP id y16-20020a0cead0000000b0067a15dda99fmr17336358qvp.46.1701190275781; Tue, 28 Nov 2023 08:51:15 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id i7-20020ad44107000000b0067a254f0febsm3547508qvp.146.2023.11.28.08.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 08:51:15 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH 1/2] c++: casting array prvalue [PR112658, PR94264] Date: Tue, 28 Nov 2023 11:51:11 -0500 Message-ID: <20231128165112.2571430-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.rc1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.9 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,RCVD_IN_SORBS_WEB,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 List-Id: Bootstrapped and regtested on x86-64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Here we deem the array-to-pointer conversions in both calls as invalid, but we fail to issue a diagnostic for the second call, ultimately because cp_build_c_cast doesn't replay errors from build_const_cast_1. This means the second call get silently discarded leading to wrong/unexpected code. This patch fixes this issue. I'm not sure if we want to accept these conversions in the first place (that's PR94264 or at least related to it), but at least we're more consistent now. PR c++/112658 PR c++/94264 gcc/cp/ChangeLog: * typeck.cc (cp_build_c_cast): If we're committed to a const_cast and the result is erroneous, call build_const_cast_1 a second time to issue errors. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-array20.C: New test. --- gcc/cp/typeck.cc | 4 +++- gcc/testsuite/g++.dg/cpp0x/initlist-array20.C | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-array20.C diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index e995fb6ddd7..b112bea4d1e 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -9209,6 +9209,8 @@ cp_build_c_cast (location_t loc, tree type, tree expr, maybe_warn_about_useless_cast (loc, type, value, complain); maybe_warn_about_cast_ignoring_quals (loc, type, complain); } + else if (complain & tf_error) + build_const_cast_1 (loc, type, value, tf_error, &valid_p); return result; } @@ -9244,7 +9246,7 @@ cp_build_c_cast (location_t loc, tree type, tree expr, to succeed. */ if (!same_type_p (non_reference (type), non_reference (result_type))) { - result = build_const_cast_1 (loc, type, result, false, &valid_p); + result = build_const_cast_1 (loc, type, result, tf_none, &valid_p); gcc_assert (valid_p); } return result; diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array20.C b/gcc/testsuite/g++.dg/cpp0x/initlist-array20.C new file mode 100644 index 00000000000..967b67023f3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array20.C @@ -0,0 +1,10 @@ +// PR c++/112658 +// { dg-do compile { target c++11 } } + +void f(int*); + +int main() { + using array = int[]; + f(array{42}); // { dg-error "address of temporary array" } + f((int*)array{42}); // { dg-error "address of temporary array" } +} -- 2.43.0.rc1