From patchwork Wed Jan 25 21:07:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 719880 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 3v7yLj5G0Dz9sCg for ; Thu, 26 Jan 2017 08:07:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="SvCxKl40"; 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=K62ymGpT+s/ltUXnegNd6msumm7RV eIygvvD9eF0pWf9cJp/No2QHaIPOD1Qj7MDOv4ilq3oSrjEjvxlLGuF34dkKOvWL y/Roj6pqV4K4RVEgIdqVj9iYAbx17OOZ0FgZzC2RMemUtkHvcr8VTot3PGX2XyMA z6waH47CKwyoTs= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=b/vtwiO7FpDTjYWTT+B4wqXkrf4=; b=SvC xKl40SyAdF//6LTRpYSSsI5NSI8MVIrfiXX8LAuiK4QaNwL8h41K33hI0UEFCQUA xMr8i9cTwQPmd5jfHB33Wq2CqZbGVnwJR6EXGjTBNHRIXs9RrIvEMDY5lEaz7lwN 5SvhrKa0sSZ5i3GXRktZ9AEzcBcV1SLD8PqPA+Zg= Received: (qmail 71937 invoked by alias); 25 Jan 2017 21:07:50 -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 71927 invoked by uid 89); 25 Jan 2017 21:07:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=decomposed 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; Wed, 25 Jan 2017 21:07:48 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B164761B9A for ; Wed, 25 Jan 2017 21:07:48 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-185.ams2.redhat.com [10.36.117.185]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0PL7k2m021604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 25 Jan 2017 16:07:48 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v0PL7iXN001038; Wed, 25 Jan 2017 22:07:44 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v0PL7iYL001037; Wed, 25 Jan 2017 22:07:44 +0100 Date: Wed, 25 Jan 2017 22:07:44 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Reject lambda closure types in decompositions (PR c++/78896) Message-ID: <20170125210744.GT1867@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! As discussed in the PR, while lambda closure types are class types, it is implementation dependent on what those class types actually contain, allowing that to be decomposed is just weird. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-01-25 Jakub Jelinek PR c++/78896 * decl.c (cp_finish_decomp): Disallow memberwise decomposition of lambda expressions. * g++.dg/cpp1z/decomp24.C: New test. Jakub --- gcc/cp/decl.c.jj 2017-01-25 17:17:51.000000000 +0100 +++ gcc/cp/decl.c 2017-01-25 19:16:19.439879509 +0100 @@ -7562,6 +7562,11 @@ cp_finish_decomp (tree decl, tree first, error_at (loc, "cannot decompose non-array non-class type %qT", type); goto error_out; } + else if (LAMBDA_TYPE_P (type)) + { + error_at (loc, "cannot decompose lambda closure type %qT", type); + goto error_out; + } else { tree btype = find_decomp_class_base (loc, type, NULL_TREE); --- gcc/testsuite/g++.dg/cpp1z/decomp24.C.jj 2017-01-25 19:19:42.536296515 +0100 +++ gcc/testsuite/g++.dg/cpp1z/decomp24.C 2017-01-25 19:19:20.000000000 +0100 @@ -0,0 +1,11 @@ +// PR c++/78896 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +int +foo () +{ + int a {10}; + auto [b] { [&a](){} }; // { dg-error "cannot decompose lambda closure type" } + return b - a; // { dg-warning "decomposition declaration only available with" "" { target c++14_down } .-1 } +}