From patchwork Thu Feb 4 08:48:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1435863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: 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=iETFujcF; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DWXJl0ygFz9sxS for ; Thu, 4 Feb 2021 19:48:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7FC033AAAC04; Thu, 4 Feb 2021 08:48:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7FC033AAAC04 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1612428512; bh=eveG5IYG4pf1nciFdnjf1xtoEPm4N1ePyeIeOfKiMyw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=iETFujcFTRUcBpQwPCgplfMu0yXxICMZ5OifVqOa401iR7qiDGqW0gkhvG/9XtIyi S++LW9YV2Vj2YwRt6DyWJGyrimlc+ENiIdy0NGk3PS9lhSh5CCHCnwkcqKI0r/uFaL JdPJgVkpZhLu6uN5/TV3Vf6JWKDS+OENtoH+gQxI= 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 [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id AD8033AAAC03 for ; Thu, 4 Feb 2021 08:48:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AD8033AAAC03 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-506-fE9WZcQPNa2p-Iha7w0qsQ-1; Thu, 04 Feb 2021 03:48:26 -0500 X-MC-Unique: fE9WZcQPNa2p-Iha7w0qsQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C60B8030B1 for ; Thu, 4 Feb 2021 08:48:25 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-197.ams2.redhat.com [10.36.112.197]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3551C10013C1; Thu, 4 Feb 2021 08:48:25 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 1148mMOF4107320 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 4 Feb 2021 09:48:22 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1148mLAc4107319; Thu, 4 Feb 2021 09:48:21 +0100 Date: Thu, 4 Feb 2021 09:48:21 +0100 To: Jason Merrill Subject: [PATCH] c++: Fix ICE with structured binding initialized to incomplete array [PR97878] Message-ID: <20210204084821.GJ4020736@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-6.4 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! We ICE on the following testcase, for incomplete array a on auto [b] { a }; without giving any kind of diagnostics, with auto [c] = a; during error-recovery. The problem is that we get too far through check_initializer and e.g. store_init_value -> constexpr stuff can't deal with incomplete array types. As the type of the structured binding artificial variable is always deduced, I think it is easiest to diagnose this early, even if they have array types we'll need their deduced type to be complete rather than just its element type. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2021-02-04 Jakub Jelinek PR c++/97878 * decl.c (check_initializer): For structured bindings, require complete type even when they have array type. * g++.dg/cpp1z/decomp54.C: New test. Jakub --- gcc/cp/decl.c.jj 2021-01-28 16:13:04.000000000 +0100 +++ gcc/cp/decl.c 2021-02-03 15:57:16.980557836 +0100 @@ -6837,7 +6837,8 @@ check_initializer (tree decl, tree init, /* We will have already complained. */ return NULL_TREE; - if (TREE_CODE (type) == ARRAY_TYPE) + if (TREE_CODE (type) == ARRAY_TYPE + && (!DECL_DECOMPOSITION_P (decl) || DECL_DECOMP_BASE (decl))) { if (check_array_initializer (decl, type, init)) return NULL_TREE; --- gcc/testsuite/g++.dg/cpp1z/decomp54.C.jj 2021-02-03 16:21:27.991237734 +0100 +++ gcc/testsuite/g++.dg/cpp1z/decomp54.C 2021-02-03 16:21:10.984428831 +0100 @@ -0,0 +1,17 @@ +// PR c++/97878 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +extern int a[]; +auto [b] { a }; // { dg-error "has incomplete type" } + // { dg-warning "only available with" "" { target c++14_down } .-1 } +auto [c] = a; // { dg-error "has incomplete type" } + // { dg-warning "only available with" "" { target c++14_down } .-1 } +extern int d[0]; +auto [e] { d }; // { dg-error "too many initializers for" } + // { dg-error "1 name provided for structured binding" "" { target *-*-* } .-1 } + // { dg-message "decomposes into 0 elements" "" { target *-*-* } .-2 } + // { dg-warning "only available with" "" { target c++14_down } .-3 } +auto [f] = d; // { dg-error "1 name provided for structured binding" } + // { dg-message "decomposes into 0 elements" "" { target *-*-* } .-1 } + // { dg-warning "only available with" "" { target c++14_down } .-2 }