From patchwork Thu Apr 5 09:06:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ville Voutilainen X-Patchwork-Id: 895311 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-475905-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Uk92E2EJ"; dkim-atps=neutral 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 40Gxlv2gwpz9ryk for ; Thu, 5 Apr 2018 19:06:49 +1000 (AEST) 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=VBbw5ZIcNGO2BEhbY9Fxg+UhnUo7VOUmfQgNGQ28EQmdgP WEODlC23iF1orFFZPmtHQfSUZfmLDxzbe6k6ZWf8JEFgLQ6Sl7sctY7SAACHIQKz N1yxFNeXEVE1IV1tb7Gn275nHDIpiQhUbdA7j6qBAC39V4ym/la4o1MbXdqnI= 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=+3+cBIzQ3eelApz3nxUj2sBVYkk=; b=Uk92E2EJJ+0Nblm86+iA z0K3ENQWSdbDil8byvLzdEcQjdQYT3hlfppeCoIaU7vuNh0+L2XoWEB40jBC1FiJ qrt8Qo+r+DFildh0PabvY2c1c4vwKmKiwmkd9TccxXHWNGlsL/LTdOFH0CvOwSXl 3hwsr9sV3nDcR4PXV3uLhQ4= Received: (qmail 111056 invoked by alias); 5 Apr 2018 09:06:42 -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 111046 invoked by uid 89); 5 Apr 2018 09:06:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=inaccessible, friend X-HELO: mail-oi0-f43.google.com Received: from mail-oi0-f43.google.com (HELO mail-oi0-f43.google.com) (209.85.218.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Apr 2018 09:06:38 +0000 Received: by mail-oi0-f43.google.com with SMTP id q71-v6so21875631oic.6 for ; Thu, 05 Apr 2018 02:06:38 -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=wTpLGlu7VPG0BwxBs2hquy+Cv35wU7jmYNF5vFwHWmw=; b=AM7q3xJ5JiPUCz0ON+QYHh8Ts3nbL0BlXUTYw6wVXZ8GlQIEg7qCj4GHds8DK1r4gp YIEy+m4s0Bh4bmlhacfL6OQHOGUp7TKgtDoVaj1/vJWJD+DIOGfTijZZGSUQHquoFE3D frCb92NqvUDXRDTB/+XxPDEMsoIHpk+Rd/7TMaZNDJQIgpQYnt/X+OAu+itqWkyi7Rni aoQdjxC688TgMjSWc6H8j7VCC366u5M5dSDBIcZQdBva0pDQdaGCRJ/VeZzsOPzhcOdz 7WR4prp97IQbhVqPGVPvKIADULAKzUlZA/AnRRSDPKfFFajsarY4YJMwLN9ouNlyVOws Qrjg== X-Gm-Message-State: ALQs6tCfJnTnD4EactjHynFCWZqa7Llzn2wlzC+pwaH9PZlmFJuByT/m +mdbx3PDrA9xUH7uI1ZEwlwv9NpcjdPOAgwz65b7rQ== X-Google-Smtp-Source: AIpwx4/Mvmc5LJSjGmEGTd4QhkppAlbTIYqNDg9gaYOS/8O8kGAMp4dNT3eahJhQQVfY8n+bATJGW3vvnMa1jIL44Eg= X-Received: by 2002:aca:f204:: with SMTP id q4-v6mr12625719oih.61.1522919197168; Thu, 05 Apr 2018 02:06:37 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:183a:0:0:0:0:0 with HTTP; Thu, 5 Apr 2018 02:06:36 -0700 (PDT) From: Ville Voutilainen Date: Thu, 5 Apr 2018 12:06:36 +0300 Message-ID: Subject: [C++ PATCH] Implement P0969 To: gcc-patches@gcc.gnu.org, Jason Merrill Tested on Linux-PPC64. 2018-04-05 Ville Voutilainen gcc/cp Implement P0969 * decl.c (find_decomp_class_base): Check accessibility instead of declared access, adjust diagnostic. testsuite/ Implement P0969 * g++.dg/cpp1z/decomp4.C: Adjust. * g++.dg/cpp1z/decomp38.C: New. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 1a100c8..2cde65b 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7322,9 +7322,9 @@ find_decomp_class_base (location_t loc, tree type, tree ret) inform (DECL_SOURCE_LOCATION (field), "declared here"); return error_mark_node; } - else if (TREE_PRIVATE (field) || TREE_PROTECTED (field)) + else if (!accessible_p (type, field, true)) { - error_at (loc, "cannot decompose non-public member %qD of %qT", + error_at (loc, "cannot decompose inaccessible member %qD of %qT", field, type); inform (DECL_SOURCE_LOCATION (field), TREE_PRIVATE (field) diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp38.C b/gcc/testsuite/g++.dg/cpp1z/decomp38.C new file mode 100644 index 0000000..fc69c02 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp38.C @@ -0,0 +1,48 @@ +// { dg-additional-options -std=c++17 } +// { dg-do compile } + +class X +{ + int a, b; + void f() + { + auto[x,y] = *this; + } +}; + +class X2 +{ + int a, b; + void f(X2& other) + { + auto[x,y] = other; + } +}; + +struct X3 +{ + friend void foo(); +private: + int a; +}; + +void foo() +{ + X3 x; + auto [a] = x; +} + +struct X4 +{ + int a; +}; + +struct X5 : private X4 +{ + friend void foo2(); +}; + +void foo2() { + X5 x; + auto [a] = x; +} diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp4.C b/gcc/testsuite/g++.dg/cpp1z/decomp4.C index e50b882..69b5455 100644 --- a/gcc/testsuite/g++.dg/cpp1z/decomp4.C +++ b/gcc/testsuite/g++.dg/cpp1z/decomp4.C @@ -18,10 +18,10 @@ test (A &a, B &b, C &c, D &d, E &e, F &f, G &g, H &h, I &i) // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } .-1 } auto [ k ] { b }; // { dg-error "cannot decompose class type 'B' because it has an anonymous union member" } // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } .-1 } - auto [ l, l2 ] = c; // { dg-error "cannot decompose non-public member 'C::b' of 'C'" } + auto [ l, l2 ] = c; // { dg-error "cannot decompose inaccessible member 'C::b' of 'C'" } // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } .-1 } auto [ m ] = d; // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } } - auto [ n ] { e }; // { dg-error "cannot decompose non-public member 'E::a' of 'E'" } + auto [ n ] { e }; // { dg-error "cannot decompose inaccessible member 'E::a' of 'E'" } // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } .-1 } auto [ o ] { f }; // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } } auto & [ p ] { g }; // { dg-error "cannot decompose class type 'G': both it and its base class 'F' have non-static data members" }