From patchwork Tue Nov 5 16:02:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 2006973 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=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=L0hZUVJG; 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 4XjY8G3tfwz1xyM for ; Wed, 6 Nov 2024 03:05:17 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 780DC3857727 for ; Tue, 5 Nov 2024 16:05:15 +0000 (GMT) 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 ESMTP id 5BD0C3858027 for ; Tue, 5 Nov 2024 16:04:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5BD0C3858027 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 5BD0C3858027 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=1730822694; cv=none; b=A2Ipnjkmnh8hUYxjJByPQAMHFCHMVjTdiuGlJIF7OXitOYBfLygZ3yheFSKhW4vO47Otcmv6oNUhiWsIXQ8Te4vMit7DGFbCuf95BUL2FZ3pnfjpoE8bz2zBWptveyNPsVT/LO3pkag+hQJ5BFisI6SCHatAz8+29SCkx8Eh3Tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730822694; c=relaxed/simple; bh=zm+UEAOEuP05VUlU78SaAsGoy6QiAdrOYbwLGfYmKjU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QWCc3gYNDmtUX2uRb6FrXtdgbphEQPZGD0xmwwKc4kmEAKJrY8DSv9ICxhGbz/MkX5NNJzvvATa53gcP0d9ppZL4h4j6LPTzKsH24b2X937W+N4FQV969Nsm90nJucPeKCY28Msrmpavzs6HK+JIYAi7wciJxx+YZPe1DVLYHx0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730822692; 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=Uc/yF1KbmmJJK3aBWB6U4vTXP2xD6i0AmLaXde3ha5o=; b=L0hZUVJGTSbcCpnIyVZE8wOc2+NPT8i/2Dn8Y2UdqJWiTqGdHnXf4glyhvamgPHqgXGSea u5IAn2t2Kh+8KyIa8ZE9H7HWovA3hFJqEHSXUqabGHYO87iswE1K7/qB1K7W08ltQd0dM2 9wJVMqu5hTgQNAe2UVHNkQ+mXIjBkT0= Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-323-pq_PcivvOommDoO3CW_i-g-1; Tue, 05 Nov 2024 11:04:50 -0500 X-MC-Unique: pq_PcivvOommDoO3CW_i-g-1 Received: by mail-oi1-f199.google.com with SMTP id 5614622812f47-3e6575658e9so5009598b6e.2 for ; Tue, 05 Nov 2024 08:04:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822690; x=1731427490; 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=Uc/yF1KbmmJJK3aBWB6U4vTXP2xD6i0AmLaXde3ha5o=; b=eurKv/UZ1TOz/7ZvEw1jjBdLLCI457CTsXfoco0c02P3myIR6I+HoFCBh1fUaB6Og5 z9YfWHUDqPE8gTMIyg0qvme3x+dNCH0IE1zbRd2aJy8RT+nET94u1Mei5Xf7enukeuYq 4kATC0kaL867/+y7BY3nPcJM80D8ENuYS/jvFxugnzJ09Ts1nHBCcqEYbG76GFAUWXQU JwwXAqQ60n/HGvliBglv+YSw5En/kjLDZKM5loxSAAJooWxIWR6nN9mm+nucXoTjajPe 1MYssPgru7buggxaeQaQm+kSMhHw6qljX639v+pgddXYo71E3F2x7ZTGuMQo3tZiAf+7 FLxQ== X-Gm-Message-State: AOJu0YwP9Jxbc6fHF7zQxAHmiMC1hgu5gtk5ZWhaWrX/rW9UwhPnn7Pf ZggAPU0m1dBhkcGwFmiW5LsT+XRnyCoVryyhM6+q+G1tR/AoqHO7WL6eBUdu8bbzpp/JlAySess Ykq0PfMpkkfj4tF2lvb5CETs/qUgTwEzHPIab9OyWXjxjuUoFgTdWjvgOaSHL6xxLhpwuAgIyuk WSz9nipQ+3Dzr/Nxa0G13C/BAhLHlhnN6aKoY= X-Received: by 2002:a05:6808:399b:b0:3e6:f30:f8ba with SMTP id 5614622812f47-3e6384c4d53mr37677179b6e.29.1730822689780; Tue, 05 Nov 2024 08:04:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFks1d/cH+haNRccNZj5qJzSiv5mI9Rs3KpxzVukoUZ+aaBtZfAs8yi8f5q6o31TenNfgTsmg== X-Received: by 2002:a05:6808:399b:b0:3e6:f30:f8ba with SMTP id 5614622812f47-3e6384c4d53mr37677140b6e.29.1730822689344; Tue, 05 Nov 2024 08:04:49 -0800 (PST) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3e6612594desm2550707b6e.53.2024.11.05.08.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 08:04:48 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Cc: Marek Polacek Subject: [pushed] c++: allow array mem-init with -fpermissive [PR116634] Date: Tue, 5 Nov 2024 11:02:49 -0500 Message-ID: <20241105160446.286616-1-jason@redhat.com> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk and 14. -- 8< -- We've accidentally accepted this forever (at least as far back as 4.7), but it's always been ill-formed; this was PR59465. And we didn't accept it for scalar types. But rather than switch to a hard error for this code, let's give a permerror so affected code can continue to work with -fpermissive. PR c++/116634 gcc/cp/ChangeLog: * init.cc (can_init_array_with_p): Allow PR59465 case with permerror. gcc/testsuite/ChangeLog: * g++.dg/diagnostic/aggr-init1.C: Expect warning with -fpermissive. * g++.dg/init/array62.C: Adjust diagnostic. * g++.dg/init/array63.C: Adjust diagnostic. * g++.dg/init/array64.C: Adjust diagnostic. --- gcc/cp/init.cc | 4 +++- gcc/testsuite/g++.dg/diagnostic/aggr-init1.C | 3 ++- gcc/testsuite/g++.dg/init/array62.C | 2 +- gcc/testsuite/g++.dg/init/array63.C | 2 +- gcc/testsuite/g++.dg/init/array64.C | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) base-commit: 6543a214485c0a722152e34de37424f9a0104bbb diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index 12c673efb2a..62b3d6f6ce9 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -967,7 +967,9 @@ can_init_array_with_p (tree type, tree init) return true; } - return false; + permerror (input_location, "array must be initialized " + "with a brace-enclosed initializer"); + return true; } /* Initialize MEMBER, a FIELD_DECL, with INIT, a TREE_LIST of diff --git a/gcc/testsuite/g++.dg/diagnostic/aggr-init1.C b/gcc/testsuite/g++.dg/diagnostic/aggr-init1.C index 3c32124d6fd..906d2564bda 100644 --- a/gcc/testsuite/g++.dg/diagnostic/aggr-init1.C +++ b/gcc/testsuite/g++.dg/diagnostic/aggr-init1.C @@ -1,5 +1,6 @@ // PR c++/116634 // { dg-do compile { target c++11 } } +// { dg-additional-options -fpermissive } namespace std { using size_t = decltype(sizeof(42)); @@ -20,7 +21,7 @@ private: template struct Any final { constexpr - Any(ConstString (&&_vec)[N]) noexcept: vec(_vec){} // { dg-error "array" } + Any(ConstString (&&_vec)[N]) noexcept: vec(_vec){} // { dg-warning "array" } ConstString vec[N]; }; diff --git a/gcc/testsuite/g++.dg/init/array62.C b/gcc/testsuite/g++.dg/init/array62.C index 2a786a36e4e..6d3935d7a66 100644 --- a/gcc/testsuite/g++.dg/init/array62.C +++ b/gcc/testsuite/g++.dg/init/array62.C @@ -4,7 +4,7 @@ struct string {} a[1]; struct pair { string s[1]; - pair() : s(a) {} // { dg-error "invalid initializer for array member" } + pair() : s(a) {} // { dg-error "array must be initialized" } }; struct S { diff --git a/gcc/testsuite/g++.dg/init/array63.C b/gcc/testsuite/g++.dg/init/array63.C index 57e98056168..96bc9a64b26 100644 --- a/gcc/testsuite/g++.dg/init/array63.C +++ b/gcc/testsuite/g++.dg/init/array63.C @@ -7,7 +7,7 @@ struct I { struct O { I a[2]; static I const data[2]; - O() : a(data){} // { dg-error "invalid initializer for array member" } + O() : a(data){} // { dg-error "array must be initialized" } }; I const O::data[2] = {true, false}; diff --git a/gcc/testsuite/g++.dg/init/array64.C b/gcc/testsuite/g++.dg/init/array64.C index e0afdfab39a..bbdd70c6df8 100644 --- a/gcc/testsuite/g++.dg/init/array64.C +++ b/gcc/testsuite/g++.dg/init/array64.C @@ -16,7 +16,7 @@ typedef UserType Array[my_size]; class Foo { public: - Foo(Array& m) : m_(m) {}; // { dg-error "invalid initializer for array member" } + Foo(Array& m) : m_(m) {}; // { dg-error "array must be initialized" } private: Array m_; };