From patchwork Tue Mar 20 13:55:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 888238 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-475026-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="cqwNBWWq"; 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 405Dwn06mXz9s19 for ; Wed, 21 Mar 2018 00:55:52 +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=mG8rbFuZ8oq6KUI4t5r8PJkhUuDC4mU1+L/Bly7NvKmG/S58jq olcYuT4V9ekTAvGwhxyuFmtI2BOt19AqfhqdaBxq48I4Aih+mFKMFVSKeP+fArTH 3J5cHXALFcymGGZR1yVIkh6KTfcbPCNlrY369p8wPRI4QLGmpG6kZnsRQ= 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=vKcxmY8UnGwYaVL04TggaLIS28Y=; b=cqwNBWWqlYxePuZ6VWdA 3SEE8PCb4gs72P+C/dSZDxNwghp7FxyeqeobJuB7Jw/mLGgXSAOF8pmRSOhaAOwk qCr9pItnLu3cPbZ3vrQFVm/CK/dDY6BeUwIqcHx7xTj8JPwRCl4Pem6fvsh7niZs 1D7OaneP2Nc3Od0TrKh0C+U= Received: (qmail 20482 invoked by alias); 20 Mar 2018 13:55:46 -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 20070 invoked by uid 89); 20 Mar 2018 13:55:45 -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=H*r:10d X-HELO: mail-yw0-f182.google.com Received: from mail-yw0-f182.google.com (HELO mail-yw0-f182.google.com) (209.85.161.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Mar 2018 13:55:43 +0000 Received: by mail-yw0-f182.google.com with SMTP id y203so529330ywg.5 for ; Tue, 20 Mar 2018 06:55:43 -0700 (PDT) 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=vR2t1vt0DWifxKTi8vqQpTXOsqziOHjC78e3Zwcu+9M=; b=Lce3hsIkg9QdFCMqVeBV/Vmm5MXmYrugRKDrRcFcooOGXtfZTotL8OpoqkBf6tLS+j XZosrln6LCtB0tTraFd2lIkd58v3dASysV9IvBxQzjLkCS5z33e+J4gqX7f/GE7oeAwb exIkdeBKQQUNqt3jLBiHuX6rBHqTAI82EToFAObLtMPhBXs//7WynuH25OKv8AwtAgFP sYUEDy3kXlq56kbWMPEJYsi+FX4Pv2eS2gXBQpL3OyeVClGfeBsq8EmU4sKymXjpV37J 6IIxVljBfC+/ueYnSUYWBG1sEEo1FQ27/NxM1QmDLhmBqP3G1hbZ/mBrzePeWLUYgWpL U22Q== X-Gm-Message-State: AElRT7EAkxyWeBx4hIRhxzLZyvTTmlTyTMNQYgCnRh45nIuMFSFHChn/ O4qx1Ux3SqRuGk03aLM9o3w= X-Google-Smtp-Source: AG47ELvjNK9yXbUi5LO+vj+9b/BnZeDn57eJWiOX1oYv0s793SV8lnXyEdeYqOwiz+MU7d+/vFqg5Q== X-Received: by 10.129.233.1 with SMTP id d1mr9414172ywm.58.1521554141904; Tue, 20 Mar 2018 06:55:41 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::2:ec9e]) by smtp.googlemail.com with ESMTPSA id d135sm660425ywh.2.2018.03.20.06.55.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Mar 2018 06:55:41 -0700 (PDT) To: GCC Patches , Jason Merrill From: Nathan Sidwell Subject: [PR c++/84962] ICE with anon-struct member Message-ID: Date: Tue, 20 Mar 2018 09:55:39 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 This fixes the 84962 ICE, which is where we name a member function of an anon-struct in the width specifier of a bitfield. The problem is that when permissive we allow some of this strangeness. Prior to my lookup changes, we only added TYPE_FIELDS and we still do that. Trouble is that now contains member functions, and badness happens. The fix is to add the member_vec members, if that exists, which takes care of overloaded. Due to history, we don't check some of the anon-struct restrictions until the outer struct is complete. That's partly historical and partly because we don't tell the struct parser the difference between struct X { struct { ... }; // anon-struct typedef struct { ... } name; // not an anon-struct }; It'd be nice to fix that, but not right now. However, all this stuff is an extension: 1) we permit anon-struct, not just anon-union 2) we permit things other than non-static-data members Maybe we could deprecate #2 at least? I'm not sure what its use case might be. nathan 2018-03-20 Nathan Sidwell PR c++/84962 * name-lookup.c (pushdecl_class_level): Push anon-struct's member_vec, if there is one. PR c++/84962 * g++.dg/lookup/pr84962.C: New. Index: cp/name-lookup.c =================================================================== --- cp/name-lookup.c (revision 258676) +++ cp/name-lookup.c (working copy) @@ -4490,16 +4490,30 @@ pushdecl_class_level (tree x) /* If X is an anonymous aggregate, all of its members are treated as if they were members of the class containing the aggregate, for naming purposes. */ - tree f; - - for (f = TYPE_FIELDS (TREE_TYPE (x)); f; f = DECL_CHAIN (f)) - { - location_t save_location = input_location; - input_location = DECL_SOURCE_LOCATION (f); - if (!pushdecl_class_level (f)) - is_valid = false; - input_location = save_location; + location_t save_location = input_location; + tree anon = TREE_TYPE (x); + if (vec *member_vec = CLASSTYPE_MEMBER_VEC (anon)) + for (unsigned ix = member_vec->length (); ix--;) + { + tree binding = (*member_vec)[ix]; + if (STAT_HACK_P (binding)) + { + if (!pushdecl_class_level (STAT_TYPE (binding))) + is_valid = false; + binding = STAT_DECL (binding); + } + if (!pushdecl_class_level (binding)) + is_valid = false; } + else + for (tree f = TYPE_FIELDS (anon); f; f = DECL_CHAIN (f)) + if (TREE_CODE (f) == FIELD_DECL) + { + input_location = DECL_SOURCE_LOCATION (f); + if (!pushdecl_class_level (f)) + is_valid = false; + } + input_location = save_location; } timevar_cond_stop (TV_NAME_LOOKUP, subtime); return is_valid; Index: testsuite/g++.dg/lookup/pr84962.C =================================================================== --- testsuite/g++.dg/lookup/pr84962.C (revision 0) +++ testsuite/g++.dg/lookup/pr84962.C (working copy) @@ -0,0 +1,14 @@ +// PR c++/84952 ICE with anon-struct having member fns +// { dg-do compile { target c++11 } } +// { dg-additional-options -Wno-pedantic } + +struct X { + struct + { + template int a (); + // { dg-error "can only have" "" { target *-*-* } .-1 } + }; + + int : a; // { dg-error "non-integral" } +}; +