From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 34884 invoked by alias); 23 Nov 2017 20:36:05 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 34843 invoked by uid 89); 23 Nov 2017 20:36:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KB_WAM_FROM_NAME_SINGLEWORD,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=10,5, cpp1z, sk:constru, tree_list X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Nov 2017 20:36:02 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A54336146F; Thu, 23 Nov 2017 20:36:00 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-247.ams2.redhat.com [10.36.116.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E06F0614F3; Thu, 23 Nov 2017 20:35:59 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id vANKZvvG001735; Thu, 23 Nov 2017 21:35:57 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vANKZu2X001734; Thu, 23 Nov 2017 21:35:56 +0100 Date: Thu, 23 Nov 2017 20:58:00 -0000 From: Jakub Jelinek To: Nathan Sidwell , Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix structured binding initializer checking (PR c++/81888) Message-ID: <20171123203556.GT14653@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg02165.txt.bz2 Hi! My PR81258 fix actually rejects even valid cases. The standard says that: "The initializer shall be of the form “= assignment-expression”, of the form “{ assignment-expression }”, or of the form “( assignment-expression )” Now, if the form is = assigment-expression, we can e.g. in templates end up with CONSTRUCTOR initializer which has more or fewer elements than 1. So, this patch restricts the checks to only BRACE_ENCLOSED_INITIALIZER_P and only if is_direct_init (i.e. not the = assignment-expression form). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk (and 7.x after a while)? 2017-11-23 Jakub Jelinek PR c++/81888 * parser.c (cp_parser_decomposition_declaration): Reject just BRACE_ENCLOSED_INITIALIZER_P initializers with nelts != 1 rather than all such CONSTRUCTORs, and only if is_direct_init is true. * g++.dg/cpp1z/decomp30.C: Add a test for structured binding with = {} and = { a, a } initializers. * g++.dg/cpp1z/decomp31.C: New test. --- gcc/cp/parser.c.jj 2017-11-21 20:23:01.000000000 +0100 +++ gcc/cp/parser.c 2017-11-23 15:31:44.473524252 +0100 @@ -13382,7 +13382,8 @@ cp_parser_decomposition_declaration (cp_ if (initializer == NULL_TREE || (TREE_CODE (initializer) == TREE_LIST && TREE_CHAIN (initializer)) - || (TREE_CODE (initializer) == CONSTRUCTOR + || (is_direct_init + && BRACE_ENCLOSED_INITIALIZER_P (initializer) && CONSTRUCTOR_NELTS (initializer) != 1)) { error_at (loc, "invalid initializer for structured binding " --- gcc/testsuite/g++.dg/cpp1z/decomp30.C.jj 2017-09-15 18:11:04.000000000 +0200 +++ gcc/testsuite/g++.dg/cpp1z/decomp30.C 2017-11-23 15:33:04.208552682 +0100 @@ -10,3 +10,5 @@ auto [j, k] { a, a }; // { dg-error "inv auto [l, m] = { a }; // { dg-error "deducing from brace-enclosed initializer list requires" } auto [n, o] {}; // { dg-error "invalid initializer for structured binding declaration" } auto [p, q] (); // { dg-error "invalid initializer for structured binding declaration" } +auto [r, s] = {}; // { dg-error "deducing from brace-enclosed initializer list requires" } +auto [t, u] = { a, a }; // { dg-error "deducing from brace-enclosed initializer list requires" } --- gcc/testsuite/g++.dg/cpp1z/decomp31.C.jj 2017-11-23 15:22:31.695255014 +0100 +++ gcc/testsuite/g++.dg/cpp1z/decomp31.C 2017-11-23 15:22:21.000000000 +0100 @@ -0,0 +1,18 @@ +// PR c++/81888 +// { dg-do compile { target c++17 } } + +struct S { + bool s = true; +}; + +auto [a] = S{}; + +template +bool +foo () noexcept +{ + auto [c] = T{}; + return c; +} + +const bool b = foo (); Jakub