From patchwork Fri Mar 17 18:55:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 740474 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vlF0n2PHjz9s03 for ; Sat, 18 Mar 2017 05:55:51 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="qbaq/z8h"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=mWok7rR/hqFTrCDCaQGZCDrL/35ySWZzpyqhXqrVUowUM1 7YS45eoOShzVJpllH7Hg4MYDsJQqUYHIQCqdSsQCyjlGN+Bh5bBXeYesem49TS6z rUooe99Jy+0RpfoSGS5VF40eu4rutRsh2KTPpoKCfsjZAO7OUBPY2Svv7rd08= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=az/8Yk8xoyDuN4K1mQGJyPP1uT8=; b=qbaq/z8hhXQswQRRPXVu 4WVwp+9La77CC/x3BMPY2lFAKt79GHrOBXzguLUfmpJr1/ndTK/nDSMQ8MmfvCnw k7uKAm1t3XxK0F5femqYivqw3lGp0ecTRYXSSWERVnJGDsxKzvZUhT78iW4Y9cTJ A+cXND2G+XgPJHnUnkMmWNw= Received: (qmail 76385 invoked by alias); 17 Mar 2017 18:55:41 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 76330 invoked by uid 89); 17 Mar 2017 18:55:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy= X-HELO: mail-ot0-f174.google.com Received: from mail-ot0-f174.google.com (HELO mail-ot0-f174.google.com) (74.125.82.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 17 Mar 2017 18:55:39 +0000 Received: by mail-ot0-f174.google.com with SMTP id i1so101555419ota.3 for ; Fri, 17 Mar 2017 11:55:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=lQhwAeChLlq7h5goUp1bEejThRbe9P0NhKJmWbgOYSQ=; b=sGwtTdAdBIYTNkU0Fy9dSLdD0/5p5vPhDN9e/M+TZL4uPUZIjKnpv2Az8ncVVuICIE 9VFFtuatIj31FxmO6nV7CciMUyHM3zlFB8lB26d1s/PZinDriDJGZCflgeTEAjwzLDrZ /1diYmihKBMpDR0wiTidt9EHIEu8kbSEv+eGuUVOz8pP54b7SAuGLOt1yLxTYMQqFjJ6 Sn/85fFeAl6AYEKIgwoVFlrVfyAPMQ3rL1+AN5wkCXoPlljgIBH58fDtQm53bWWQ0P4K 6IOt6a5IvlnNeg2epvbGlvqcdT5XENK3p4DPdfMvYEBxhXqM6w+do/ynN9QT8n1U5+Gm aFJw== X-Gm-Message-State: AFeK/H1H1TunZuJr0MnlvNvbHbUqRu7K/iJ41XqGWxIpYBwXdl0PINzehufEmzdOft43H2bJEYMxrG+2CtvZjORm X-Received: by 10.202.58.69 with SMTP id h66mr7724237oia.30.1489776937914; Fri, 17 Mar 2017 11:55:37 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.187.8 with HTTP; Fri, 17 Mar 2017 11:55:17 -0700 (PDT) From: Jason Merrill Date: Fri, 17 Mar 2017 14:55:17 -0400 Message-ID: Subject: C++ PATCH for c++/78345, ICE with lambda as array initializer To: gcc-patches List X-IsSubscribed: yes build_aggr_init was blithely passing most any initializer on to build_vec_init, which saw a CONSTRUCTOR and assumed that it would be of the right type, leading to an ICE. Fixed by not taking the INIT_EXPR shortcut if the CONSTRUCTOR has the wrong type. That returned us to the GCC 6 state, where we would sometimes silently accept a single expression used as an array initializer. I think that's a remnant of an extension that predates my work on the compiler, and several places already reject that pattern, so let's reject it here with a permerror. Tested x86_64-pc-linux-gnu, applying to trunk. commit 5929f60b57733160099e1d34dde93d01ae2e0319 Author: Jason Merrill Date: Fri Mar 17 07:45:02 2017 -0400 PR c++/78345 - ICE initializing array from lambda. * init.c (build_aggr_init): Check array initializer. (build_vec_init): Check the type of a CONSTRUCTOR. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 8bfcbde..ebb1245 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1617,6 +1617,10 @@ build_aggr_init (tree exp, tree init, int flags, tsubst_flags_t complain) if (init == error_mark_node) return error_mark_node; + location_t init_loc = (init + ? EXPR_LOC_OR_LOC (init, input_location) + : location_of (exp)); + TREE_READONLY (exp) = 0; TREE_THIS_VOLATILE (exp) = 0; @@ -1656,6 +1660,16 @@ build_aggr_init (tree exp, tree init, int flags, tsubst_flags_t complain) TREE_TYPE (init) = cv_unqualified (itype); from_array = (itype && same_type_p (TREE_TYPE (init), TREE_TYPE (exp))); + + if (init && !from_array + && !BRACE_ENCLOSED_INITIALIZER_P (init)) + { + if (complain & tf_error) + permerror (init_loc, "array must be initialized " + "with a brace-enclosed initializer"); + else + return error_mark_node; + } } stmt_expr = build_vec_init (exp, NULL_TREE, init, @@ -3945,6 +3959,9 @@ build_vec_init (tree base, tree maxindex, tree init, ? vec_copy_assign_is_trivial (inner_elt_type, init) : !TYPE_NEEDS_CONSTRUCTING (type)) && ((TREE_CODE (init) == CONSTRUCTOR + && (BRACE_ENCLOSED_INITIALIZER_P (init) + || (same_type_ignoring_top_level_qualifiers_p + (atype, TREE_TYPE (init)))) /* Don't do this if the CONSTRUCTOR might contain something that might throw and require us to clean up. */ && (vec_safe_is_empty (CONSTRUCTOR_ELTS (init)) diff --git a/gcc/testsuite/g++.dg/init/array48.C b/gcc/testsuite/g++.dg/init/array48.C new file mode 100644 index 0000000..27fec13 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/array48.C @@ -0,0 +1,7 @@ +// PR c++/78345 +// { dg-do compile { target c++11 } } + +struct A +{ + const int i; +} a[1] = []{}; // { dg-error "array.*init" } diff --git a/gcc/testsuite/g++.dg/torture/pr70499.C b/gcc/testsuite/g++.dg/torture/pr70499.C index 954fea5..e08c26f 100644 --- a/gcc/testsuite/g++.dg/torture/pr70499.C +++ b/gcc/testsuite/g++.dg/torture/pr70499.C @@ -1,5 +1,5 @@ // { dg-do compile } -// { dg-additional-options "-w -Wno-psabi" } +// { dg-additional-options "-w -fpermissive -Wno-psabi" } // { dg-additional-options "-mavx" { target x86_64-*-* i?86-*-* } } typedef double __m256d __attribute__ ((__vector_size__ (32), __may_alias__));