From patchwork Wed Feb 28 12:30:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 879107 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-474009-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=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CO73Gao8"; 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 3zrw0F5CFLz9s2Y for ; Wed, 28 Feb 2018 23:31:09 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=mOriI3+YkSf3p+5wSag9ox2L2xSdXLdwf5xqLWf+xtfwHPRUwV gk+20ha1YcmdSgShArxYgWgM8hmub/cksMy1VFnlGOjX8lEmondhgaYWIZtlPWBZ 3WLbzzZLkGayoI5DL/ycQGURCHydGJjbQngJexl5cyPpvh8eeB/dlhUcM= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=pwJciIueGquq+o+dsgmMVfwP+CM=; b=CO73Gao89RjmEjXWChvt ofQy+alNhnVF0QFLZJIXfEWnhcDEYic/NpCHFpkjw+aOZZ9q3mqa2YpSazQlL4p3 eCf24o7f+VLlhSqs16t/bNlklOmt4dISPuODLGJl9MXjSRO66J0rSG0nS9NwLnGn BkuTdZQABa46+Blj+bk0u5g= Received: (qmail 106475 invoked by alias); 28 Feb 2018 12:31:03 -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 106463 invoked by uid 89); 28 Feb 2018 12:31:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=HX-Received:sk:3-v6mr1 X-HELO: mail-yb0-f173.google.com Received: from mail-yb0-f173.google.com (HELO mail-yb0-f173.google.com) (209.85.213.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 Feb 2018 12:31:00 +0000 Received: by mail-yb0-f173.google.com with SMTP id t18-v6so758517ybt.0 for ; Wed, 28 Feb 2018 04:31:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=SaYQtyES4dKMTUSqv/+b/1NSs2Hw6B/sZpbKlJg/b3I=; b=kolf/Ucp+pWGnaM+pUhODNdncOfyTweFlgeNWMjxexlqk+Y1dRn6QGD/L/UhdmX7ZU Bb4xnM8oqjJilA7XbRx5LYXQevIJ3Z/0rS/LcZ6DkJrBs9CmSkAiYfI6SAeVnkEV5SSR hmUz5hpz2xIGIME1GwhovKMmRGWeybELb63MV4cHBexc0VqaB5WpNiZYCp/piAvNYo3P LIEaZsylfYjAdJuqax5JHQIiQj/hzYlWRF6tc9qqNcK5aNo1jVwFgsXhfkyaJvxQHvnE oVcaK3VKLX3pbpb2EbG3dD51unjP213C0gxjg9w3h8rt3yxN+2YZjZ36qfXwMA1os56B lI+w== X-Gm-Message-State: APf1xPCt20rJJtF8+S9ygnF8e6J9WTb5iuwT52Dd5KbCoBsZO1+wUXQ5 Z0t609JTHdEiKauYx27qVeY= X-Google-Smtp-Source: AG47ELtR+YzAvN+W2NZJAHL5xHqAIYPWt/TC3MxgmncHyOEA/M0cy9LHDdvuJ2ZpV9bVSXrTeUjE6w== X-Received: by 2002:a25:703:: with SMTP id 3-v6mr12086754ybh.513.1519821059072; Wed, 28 Feb 2018 04:30:59 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::3:acb8]) by smtp.googlemail.com with ESMTPSA id l134sm575089ywe.103.2018.02.28.04.30.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 04:30:58 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: [PR c++/84602] ICE with anon-struct Message-ID: <283ebc10-d9d9-188f-1030-bb9f99051f38@acm.org> Date: Wed, 28 Feb 2018 07:30:57 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 This fixes an ICE with anon-struct. When reimplementing this bit of name lookup, I relied on what the standard said and the completeness of the testsuite WRT extensions. Silly me. Anyway, we can just have the anon-struct lookup recurse to get_class_binding_direct, so simpler! nathan 2018-02-28 Nathan Sidwell PR c++/84602 * name-lookup.h (search_anon_aggr): Add defaulted WANT_TYPE arg. * name-lookup.c (fields_linear_search): Look in an anon-aggr regardless of want_type. (search_anon_aggr): Just use get_class_binding_direct. PR c++/84602 * g++.dg/lookup/pr84602.C: New. Index: cp/name-lookup.c =================================================================== --- cp/name-lookup.c (revision 258044) +++ cp/name-lookup.c (working copy) @@ -1162,11 +1162,10 @@ fields_linear_search (tree klass, tree n { tree decl = fields; - if (!want_type - && TREE_CODE (decl) == FIELD_DECL + if (TREE_CODE (decl) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (decl))) { - if (tree temp = search_anon_aggr (TREE_TYPE (decl), name)) + if (tree temp = search_anon_aggr (TREE_TYPE (decl), name, want_type)) return temp; } @@ -1191,26 +1190,17 @@ fields_linear_search (tree klass, tree n return NULL_TREE; } -/* Look for NAME field inside of anonymous aggregate ANON. */ +/* Look for NAME member inside of anonymous aggregate ANON. Although + such things should only contain FIELD_DECLs, we check that too + late, and would give very confusing errors if we weren't + permissive here. */ tree -search_anon_aggr (tree anon, tree name) +search_anon_aggr (tree anon, tree name, bool want_type) { gcc_assert (COMPLETE_TYPE_P (anon)); - tree ret; - - if (vec *member_vec = CLASSTYPE_MEMBER_VEC (anon)) - ret = member_vec_linear_search (member_vec, name); - else - ret = fields_linear_search (anon, name, false); - - if (ret) - { - /* Anon members can only contain fields. */ - gcc_assert (!STAT_HACK_P (ret) && !DECL_DECLARES_TYPE_P (ret)); - return ret; - } - return NULL_TREE; + tree ret = get_class_binding_direct (anon, name, want_type); + return ret; } /* Look for NAME as an immediate member of KLASS (including Index: cp/name-lookup.h =================================================================== --- cp/name-lookup.h (revision 258044) +++ cp/name-lookup.h (working copy) @@ -307,7 +307,7 @@ extern void pop_decl_namespace (void); extern void do_namespace_alias (tree, tree); extern tree do_class_using_decl (tree, tree); extern tree lookup_arg_dependent (tree, tree, vec *); -extern tree search_anon_aggr (tree, tree); +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 *find_member_slot (tree klass, tree name); Index: testsuite/g++.dg/lookup/pr84602.C =================================================================== --- testsuite/g++.dg/lookup/pr84602.C (revision 0) +++ testsuite/g++.dg/lookup/pr84602.C (working copy) @@ -0,0 +1,32 @@ +// PR c++/84602 ICE +// { dg-additional-options "-fpermissive" } + +struct X { + union { + class a; // { dg-warning "can only have" } + }; + a *b; +}; +X::a *a; + +struct Y { + union { + class a; // { dg-warning "can only have" } + int a; + }; + class a *b; +}; + +class Y::a *y; + +struct Z { + union { + // Force MEMBER_VEC creation + int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10; + class a; // { dg-warning "can only have" } + int a; + }; + class a *b; +}; + +class Z::a *z;