From patchwork Wed May 1 11:35:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1093663 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-499951-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZrBS1tgr"; 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 44vGYR1K2Gz9sNQ for ; Wed, 1 May 2019 21:35:52 +1000 (AEST) Received: (qmail 41073 invoked by alias); 1 May 2019 11:35:47 -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 40793 invoked by uid 89); 1 May 2019 11:35:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=12787 X-HELO: mail-pg1-f169.google.com Received: from mail-pg1-f169.google.com (HELO mail-pg1-f169.google.com) (209.85.215.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 01 May 2019 11:35:45 +0000 Received: by mail-pg1-f169.google.com with SMTP id d31so8193338pgl.7 for ; Wed, 01 May 2019 04:35:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=zO9uaaUs/l8CxU+mY5x2ERXBmVrEE42rMBWVFqRZniE=; b=ZrBS1tgrjww+T11BK+MjikP3ITGvxJyJFSxBQXdepv8c8jJUHV/aa1Eia1PSB8fA3R f3p5qY/VC3Btrf+/+EXRSGzXdslrJiJVUKwdUjbeveEbaGt1H97xKIqa5Cd5FJPizMWI UIviwFWRIIsM9j2zpDDsKIFhsrY6Hc5h5LXgfIvRyrX26DHjVDJ8SFOHg42a06rTHZqo iEauSqlIViMGTaO+nsVKLe9VK7slowMagULuP5mhJjL3g4QTM8uHIRj8W8L2woWez7lw r7gnnPgY1zRMcHo+qxsunXbhCf2UeklGnL97bQgYAoOSO6pdlLQOfzR78aqWjGu3zLiS zc9A== Received: from ?IPv6:2620:10d:c0a3:1407:e1aa:b68d:9549:5e9e? ([2620:10d:c091:200::1:6661]) by smtp.googlemail.com with ESMTPSA id n8sm2385114pgg.69.2019.05.01.04.35.41 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Wed, 01 May 2019 04:35:42 -0700 (PDT) Sender: Nathan Sidwell To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] Simplify class member lookup Message-ID: <41092b53-25b2-ca9e-288a-9d683e3e670b@acm.org> Date: Wed, 1 May 2019 07:35:40 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Here's another simplification I'd accumulated. The final arg to get_class_binding no longer needs to be tri-valued, a simple bool will do. This results in better diagnostics in one testcase. nathan 2019-05-01 Nathan Sidwell gcc/cp/ * name-lookup.h (get_class_binding_direct): Change final arg to bool. (get_class_binding): Likewise. * name-lookup.c (get_class_binding_direct): Replace TYPE_OR_FNS arg with WANT_TYPE bool. Simplify. (get_class_binding): Adjust final arg. * decl.c (reshape_init_class): Adjust get_class_binding calls. gcc/testsuite/ * g++.dg/cpp0x/decltype9.C: Adjust expected diagnostics. Index: gcc/cp/decl.c =================================================================== --- gcc/cp/decl.c (revision 270764) +++ gcc/cp/decl.c (working copy) @@ -5968,12 +5968,12 @@ reshape_init_class (tree type, reshape_i tree id = DECL_NAME (d->cur->index); gcc_assert (id); gcc_checking_assert (d->cur->index - == get_class_binding (type, id, false)); + == get_class_binding (type, id)); field = d->cur->index; } } else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE) - field = get_class_binding (type, d->cur->index, false); + field = get_class_binding (type, d->cur->index); else { if (complain & tf_error) Index: gcc/cp/name-lookup.c =================================================================== --- gcc/cp/name-lookup.c (revision 270764) +++ gcc/cp/name-lookup.c (working copy) @@ -1217,7 +1217,7 @@ search_anon_aggr (tree anon, tree name, Use this if you do not want lazy member creation. */ tree -get_class_binding_direct (tree klass, tree name, int type_or_fns) +get_class_binding_direct (tree klass, tree name, bool want_type) { gcc_checking_assert (RECORD_OR_UNION_TYPE_P (klass)); @@ -1233,31 +1233,26 @@ get_class_binding_direct (tree klass, tr val = member_vec_binary_search (member_vec, lookup); if (!val) ; - else if (type_or_fns > 0) - { - if (STAT_HACK_P (val)) - val = STAT_TYPE (val); - else if (!DECL_DECLARES_TYPE_P (val)) - val = NULL_TREE; - } else if (STAT_HACK_P (val)) - val = STAT_DECL (val); + val = want_type ? STAT_TYPE (val) : STAT_DECL (val); + else if (want_type && !DECL_DECLARES_TYPE_P (val)) + val = NULL_TREE; } else { - if (member_vec && type_or_fns <= 0) + if (member_vec && !want_type) val = member_vec_linear_search (member_vec, lookup); - if (type_or_fns < 0) - /* Don't bother looking for field. We don't want it. */; - else if (!val || (TREE_CODE (val) == OVERLOAD - && OVL_DEDUP_P (val))) + if (!val || (TREE_CODE (val) == OVERLOAD && OVL_DEDUP_P (val))) /* Dependent using declarations are a 'field', make sure we return that even if we saw an overload already. */ - if (tree field_val = fields_linear_search (klass, lookup, - type_or_fns > 0)) - if (!val || TREE_CODE (field_val) == USING_DECL) - val = field_val; + if (tree field_val = fields_linear_search (klass, lookup, want_type)) + { + if (!val) + val = field_val; + else if (TREE_CODE (field_val) == USING_DECL) + val = ovl_make (field_val, val); + } } /* Extract the conversion operators asked for, unless the general @@ -1278,7 +1273,7 @@ get_class_binding_direct (tree klass, tr special function creation as necessary. */ tree -get_class_binding (tree klass, tree name, int type_or_fns) +get_class_binding (tree klass, tree name, bool want_type) { klass = complete_type (klass); @@ -1308,7 +1303,7 @@ get_class_binding (tree klass, tree name } } - return get_class_binding_direct (klass, name, type_or_fns); + return get_class_binding_direct (klass, name, want_type); } /* Find the slot containing overloads called 'NAME'. If there is no Index: gcc/cp/name-lookup.h =================================================================== --- gcc/cp/name-lookup.h (revision 270764) +++ gcc/cp/name-lookup.h (working copy) @@ -303,8 +303,8 @@ extern void do_namespace_alias (tree, tr extern tree do_class_using_decl (tree, tree); extern tree lookup_arg_dependent (tree, tree, vec *); extern tree search_anon_aggr (tree, tree, bool = false); -extern tree get_class_binding_direct (tree, tree, int type_or_fns = -1); -extern tree get_class_binding (tree, tree, int type_or_fns = -1); +extern tree get_class_binding_direct (tree, tree, bool want_type = false); +extern tree get_class_binding (tree, tree, bool want_type = false); extern tree *find_member_slot (tree klass, tree name); extern tree *add_member_slot (tree klass, tree name); extern void resort_type_member_vec (void *, void *, Index: gcc/testsuite/g++.dg/cpp0x/decltype9.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/decltype9.C (revision 270764) +++ gcc/testsuite/g++.dg/cpp0x/decltype9.C (working copy) @@ -2,8 +2,7 @@ // { dg-do compile { target c++11 } } template struct A { // { dg-message "defined here" } - static int i; + static int i; // { dg-message "candidate" } }; template int A::i(decltype (A::i)); // { dg-error "no declaration" } -// { dg-message "no functions" "note" { target *-*-* } .-1 }