From patchwork Wed Apr 4 22:26:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ville Voutilainen X-Patchwork-Id: 895179 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-475890-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="QscH1Evg"; 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 40GgYY5fvnz9s0t for ; Thu, 5 Apr 2018 08:26:55 +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=GXbSAv/BohJtbY09qOokuonYiO9+HSGGfF57SmBExEMjrV 3uO5Q/ztkpoqqSP0ZHTM+TAZSi4NI7emz5vNNm4OveB3RWZGPBMXjsX9hhBiPl9w TqDWgFRimBy85wRn95awNuAncRfxkOJJkF0OXCiPzqunW9trqyZiB0/r4Up9c= 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=TweGnuKMr6LncWg6d4XLkvo9bn4=; b=QscH1Evggp0oFWQ+uiOw PC9KPhHBlys9Kt4cUOuWcWr/x3h/brGzLsn93RmhW6vM8KIoh6dsZKP4lWuS119A 93oCJxjw15M2bZU6c/Lq5XNYfK4cWcx4OzMlOlJNPky+VkT2kutq9nvXzXC4s10V ieKL21fd65iFS5YVEzST6Qw= Received: (qmail 41283 invoked by alias); 4 Apr 2018 22:26:48 -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 41272 invoked by uid 89); 4 Apr 2018 22:26:47 -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=parm, PARM_DECL, parm_decl X-HELO: mail-oi0-f45.google.com Received: from mail-oi0-f45.google.com (HELO mail-oi0-f45.google.com) (209.85.218.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Apr 2018 22:26:46 +0000 Received: by mail-oi0-f45.google.com with SMTP id c3-v6so20776903oib.5 for ; Wed, 04 Apr 2018 15:26:46 -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=qOBYYW+8N2a8bJNQWljdUvv0QdZglILwFUA68mL/u/A=; b=FMHa/O8CXYRX7j4bLvXLbGuYr/0pXdrk3TilEoFZ4Vn4iraLuFv7RA65XZ66hs6pV1 5gaTD2TLKOrF6VeknjvdbJJ2QXoYe03z2d9vT/GsaCxVz7+pZw7GcFh+z6/80znTbTiJ 54pm1T9Mq4Y6rXkcJbwfX0OlFZ5RRY30TRzSrfJjSv1YvxnedGPo5Jvs+3fvei0SVoFC ADNdRu5SSRgMnKUBVZ5gpOwMxMW9gthWmFGWUwcdoM0cZ6rj9wf2axauMisq0yzca4I1 g9On/vd7R6Z7kDblhIh26uPKOMpgaddVq/A0ebuwuKP/6SgY9QBz5kzyjPVffi9rLMjS b6xA== X-Gm-Message-State: ALQs6tCfV4AR8QaI+WIcUKb2KxTctnZcpRKwpMxZyj5vkTr8zgZi0/Mv kte/biXKMAveWlp6YDobyhyz/jbB932M9DTgcMcXfw== X-Google-Smtp-Source: AIpwx48ZMH9MFsQnA/mUM2grGv4B+eHWTy3IJbfjlexroOC5517RHg12Lfhk8KHesZ7y7HW3Iy9ZeV4I/XLzDagb0Ww= X-Received: by 2002:aca:c486:: with SMTP id u128-v6mr11606902oif.117.1522880804877; Wed, 04 Apr 2018 15:26:44 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:183a:0:0:0:0:0 with HTTP; Wed, 4 Apr 2018 15:26:44 -0700 (PDT) From: Ville Voutilainen Date: Thu, 5 Apr 2018 01:26:44 +0300 Message-ID: Subject: [C++ PATCH] Implement P0961 To: gcc-patches@gcc.gnu.org, Jason Merrill Tested on Linux-PPC64. 2018-04-05 Ville Voutilainen gcc/cp Implement P0961 * decl.c (get_tuple_decomp_init): Check the templatedness of a member get. testsuite/ Implement P0961 * g++.dg/cpp1z/decomp10.C: Adjust. * g++.dg/cpp1z/decomp37.C: New. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 746084c..1a100c8 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7432,7 +7432,24 @@ get_tuple_decomp_init (tree decl, unsigned i) tree fns = lookup_qualified_name (TREE_TYPE (e), get_id, /*type*/false, /*complain*/false); - if (fns != error_mark_node) + bool use_member_get = false; + + for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter) + { + tree fn = *iter; + if (TREE_CODE (fn) == TEMPLATE_DECL) + { + tree tparms = DECL_TEMPLATE_PARMS (fn); + tree parm = TREE_VEC_ELT (TREE_VALUE (tparms), 0); + if (TREE_CODE (TREE_VALUE (parm)) == PARM_DECL) + { + use_member_get = true; + break; + } + } + } + + if (use_member_get) { fns = lookup_template_function (fns, targs); return build_new_method_call (e, fns, /*args*/NULL, diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp10.C b/gcc/testsuite/g++.dg/cpp1z/decomp10.C index 6ed9272..b4169d3 100644 --- a/gcc/testsuite/g++.dg/cpp1z/decomp10.C +++ b/gcc/testsuite/g++.dg/cpp1z/decomp10.C @@ -20,7 +20,7 @@ void f3() { auto [ x ] = a3; } // { dg-error "get" } struct A3a { int i,j; int get(); } a3a; template<> struct std::tuple_size { enum { value = 1 }; }; -void f3a() { auto [ x ] = a3a; } // { dg-error "get<0>" } +void f3a() { auto [ x ] = a3a; } // { dg-error "get" } struct A3b { int i,j; } a3b; int get(A3b&&); diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp37.C b/gcc/testsuite/g++.dg/cpp1z/decomp37.C new file mode 100644 index 0000000..dc47908 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp37.C @@ -0,0 +1,62 @@ +// { dg-additional-options -std=c++17 } +// { dg-do compile } + +#include +#include +#include + +struct X : private std::shared_ptr +{ + std::string fun_payload; +}; + +template std::string& get(X& x) +{ + if constexpr(N==0) return x.fun_payload; +} + +namespace std { + template<> class tuple_size : public std::integral_constant {}; + template<> class tuple_element<0, X> {public: using type = std::string;}; +} + +struct X2 : private std::shared_ptr +{ + int fun_payload; + template void get(); +}; + +template int& get(X2& x) +{ + if constexpr(N==0) return x.fun_payload; +} + +namespace std { + template<> class tuple_size : public std::integral_constant {}; + template<> class tuple_element<0, X2> {public: using type = int;}; +} + +class X3 +{ + double fun_payload; +public: + template double& get() + { + if constexpr(N==0) return fun_payload; + } +}; + +namespace std { + template<> class tuple_size : public std::integral_constant {}; + template<> class tuple_element<0, X3> {public: using type = double;}; +} + +int main() +{ + X x; + auto& [b1] = x; + X2 x2; + auto& [b2] = x2; + X3 x3; + auto& [b3] = x3; +}