From patchwork Tue Jan 10 19:03:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 713386 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 3tyhJP00LTz9t14 for ; Wed, 11 Jan 2017 06:03:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="HaU8Nyrd"; 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=Q0j0eEsdEu+W2zEGrHQfk3u/dcptOvghFstN14Anl6rpq+ vQbY6z+6Hv9+txejOHb3ft4J00mOWknDQxwVvC9ESZ4/aQCnVx6maKnunxYMxzjU 0fL21AuilwgEpIPVSL4drK2KUcDm7iuMncai4Y0DFUIbFxZez3UCgztuhlkNw= 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=Sy8SvqRwvLEY+lgBEyC3EEmdlIw=; b=HaU8Nyrdw0IuIpe+otfB FzTBzvj2TQYfm9aYwBCf1eZr+aFh4OzFVhMndm5Qjk9ZgfA3hJHEnNM1teRBMxhg OnzFmZd58X4h8iLieD9s8u/69nhMz7XcD4iCwcEUMsTMWO6xjevTI7peNGZgOq+7 YmHkWj5hXG8miTuGQarYnP4= Received: (qmail 16758 invoked by alias); 10 Jan 2017 19:03:38 -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 15953 invoked by uid 89); 10 Jan 2017 19:03:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=no version=3.3.2 spammy=ij, TREE_LIST, tree_list, sk:cp_lexe X-HELO: mail-oi0-f53.google.com Received: from mail-oi0-f53.google.com (HELO mail-oi0-f53.google.com) (209.85.218.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Jan 2017 19:03:37 +0000 Received: by mail-oi0-f53.google.com with SMTP id w204so60669482oiw.0 for ; Tue, 10 Jan 2017 11:03:36 -0800 (PST) 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=7F3XEciBnOddozyWK04wDHmvDCgk88Xevdm4G8NJUVo=; b=uPnn/y6dv8TwOr+MXaenSn6mOfmg9a7qEYYZx4ERrID2PymAKsDf3jBTbXmU2tBHRj yv3z3a9dJpfUc+GOmiENKKkcNKxAQOmF7TYZ4zunXsnluomwIrrIf3oocFPNZ0sdmGk1 Em/3Bm0Uq2XyML0X15mkCL2wr1o3NEdlI8J3764RlmIqxCgjBo9f6cRiemyWU4aUbGiu HLE/DcBS02//oTCiTh7uc0lqF2vznCr+DWgk2DR2JgNe+osHESDuvN3hv++UhcC0k2L/ pui0pCueOIon+h+XbqYp7XkYla1Id20bxQI1CljRt56XxkgyIw+Wv1AN0EtU/8Cd8Eio O6sA== X-Gm-Message-State: AIkVDXJbKQe3Cgf7zq1ONexw3UTLqjxouQBsXe15QCsHlgVQr1M7pnHlC32Rk20u3xu5KqoBqu21zTm4RprPxXjr X-Received: by 10.157.46.228 with SMTP id w91mr2291200ota.31.1484075015023; Tue, 10 Jan 2017 11:03:35 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.173.104 with HTTP; Tue, 10 Jan 2017 11:03:14 -0800 (PST) From: Jason Merrill Date: Tue, 10 Jan 2017 14:03:14 -0500 Message-ID: Subject: C++ PATCH for C++17 NB comment FI20 (parenthesized initialization with decomposition) To: gcc-patches List X-IsSubscribed: yes The FI20 comment on the decomposition declarations proposal complained that the syntax unnecessarily excluded parenthesized initialization. This patch implements the resolution. Tested x86_64-pc-linux-gnu, applying to trunk. commit 749ec367e50b356a40fd41a3daae10d9d948062b Author: Jason Merrill Date: Mon Jan 9 17:33:42 2017 -0500 FI 20, decomposition declaration with parenthesized initializer. * parser.c (cp_parser_decomposition_declaration): Use cp_parser_initializer. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index aa045c4..4517313 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -12923,7 +12923,7 @@ cp_parser_simple_declaration (cp_parser* parser, /* Helper of cp_parser_simple_declaration, parse a decomposition declaration. decl-specifier-seq ref-qualifier [opt] [ identifier-list ] - brace-or-equal-initializer ; */ + initializer ; */ static tree cp_parser_decomposition_declaration (cp_parser *parser, @@ -13022,21 +13022,12 @@ cp_parser_decomposition_declaration (cp_parser *parser, || cp_lexer_next_token_is_not (parser->lexer, CPP_COLON)) { bool non_constant_p = false, is_direct_init = false; - tree initializer; *init_loc = cp_lexer_peek_token (parser->lexer)->location; - /* Parse the initializer. */ - if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)) - { - initializer = cp_parser_braced_list (parser, &non_constant_p); - CONSTRUCTOR_IS_DIRECT_INIT (initializer) = 1; - is_direct_init = true; - } - else - { - /* Consume the `='. */ - cp_parser_require (parser, CPP_EQ, RT_EQ); - initializer = cp_parser_initializer_clause (parser, &non_constant_p); - } + tree initializer = cp_parser_initializer (parser, &is_direct_init, + &non_constant_p); + if (TREE_CODE (initializer) == TREE_LIST) + initializer = build_x_compound_expr_from_list (initializer, ELK_INIT, + tf_warning_or_error); if (decl != error_mark_node) { diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp20.C b/gcc/testsuite/g++.dg/cpp1z/decomp20.C new file mode 100644 index 0000000..8831b71 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp20.C @@ -0,0 +1,10 @@ +// { dg-options -std=c++1z } + +struct A { int i,j; }; + +A f(); + +int main() +{ + auto [i,j] (f()); +}