From patchwork Wed Aug 23 19:47:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 805160 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-460837-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="lMBHN1V4"; 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 3xcyd20gX0z9s83 for ; Thu, 24 Aug 2017 05:47:33 +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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=gIGxTYd3wFpRkEmgaNnW5LPgaxjK33xXn1qW6FiH6R/+LtZz/j XsTFDnq34ioDRGToN+p+oFAYceAbLNJBxPnowSCmOHc85azX4yw1Oq7ejaf/U/1Y yrlBkfVsW4WhFIxX76yTotm36qvMCOfTy4VryC1MTiDQ2FjEc7koTFMA0= 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=hR8AYBCWCl/VB3UphFZC93Akmoo=; b=lMBHN1V48mfWYol1Ocev ferlWKqQhHkFtMrH/b5plTrtRUd2suSeuZQw9DHJqyHML/Ngo6+/7y/5aJPJQMVY O/owGEbFS7IiI6fqYk6Jnu5EFhI661dJALHmgmZmJpnrJJRbLjD4oPt59AEqLCSf h+O5Y1WsrbaIvTHbbL6iXPM= Received: (qmail 45285 invoked by alias); 23 Aug 2017 19:47:25 -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 42748 invoked by uid 89); 23 Aug 2017 19:47:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=sE, closure, reversing X-HELO: mail-yw0-f179.google.com Received: from mail-yw0-f179.google.com (HELO mail-yw0-f179.google.com) (209.85.161.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Aug 2017 19:47:19 +0000 Received: by mail-yw0-f179.google.com with SMTP id y64so6824895ywf.3 for ; Wed, 23 Aug 2017 12:47:19 -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=Rhi/Gtn2tNB7M7wlpWzm/p7Wtxj+ZYxYRYoqyWDBcc8=; b=Kp4xusVDvPQ2kvzOhQaA4Ln3v/Kutup+ccQLC+qBve3ixbFH4OfSpJQMT/ZlEUVaGA ws454Z5UsUCn/relQkMQpXCsgA0D3UbUYEQfWtYfur85lISOmm6A05X5Ap9/Jc6JU5Jn tceT3/iGRbttlAx6ZHjroC0LQnvhTggFvSPAFpHjd5GirHb1+kSWZZM9yEtXKBaxoj8G qnu6t6GXWVOx7N7ULzsnUH2db+60/cQdPPA8pczGNNtNv/rk3FqXnv3HJOGZku26Q9ke qddeM/n1cUBEfAenoxFWvc++GQKhmEZbdV1J+m/PCVPGKZoTxA+qUAuTvOQT9SYuRU5a JdVg== X-Gm-Message-State: AHYfb5h0Ce4+ZpegO0lnje2eGlkd9vh3pkDCftBIFZZqr6e5vDi37xPz DtciDplfG8biCg== X-Received: by 10.37.98.148 with SMTP id w142mr3245206ybb.350.1503517637741; Wed, 23 Aug 2017 12:47:17 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a1:1102:495f:7267:5ff:a250? ([2620:10d:c091:180::1:ac9e]) by smtp.googlemail.com with ESMTPSA id m5sm593932ywi.1.2017.08.23.12.47.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Aug 2017 12:47:17 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] finish-member-decl cleanups Message-ID: <2326d48f-916c-6793-bb09-d3d376c5d9a9@acm.org> Date: Wed, 23 Aug 2017 15:47:15 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 And here's one for finish-member-declaration. I move inhibiting of a USING_DECL's debug info out of a non-fn member-specific block, and unconditionally set C++ linkage. Now that Java linkage is no longer a thing, we were effectively doing: if (bool_thing == false) bool_thing = true; After adding a member fn or a non-fn member we perform similar actions in duplicated code blocks. This commonizes that adding of the DECL. applied to trunk. nathan 2017-08-23 Nathan Sidwell * semantics.c (finish_member_declaration): Move USING_DECL check earlier. Always set C++ linkage. Commonize TYPE_FIELD and template decl list insertion. Index: semantics.c =================================================================== --- semantics.c (revision 251313) +++ semantics.c (working copy) @@ -3025,7 +3025,13 @@ finish_member_declaration (tree decl) if (TREE_CODE (decl) != CONST_DECL) DECL_CONTEXT (decl) = current_class_type; - /* Check for bare parameter packs in the member variable declaration. */ + if (TREE_CODE (decl) == USING_DECL) + /* For now, ignore class-scope USING_DECLS, so that debugging + backends do not see them. */ + DECL_IGNORED_P (decl) = 1; + + /* Check for bare parameter packs in the non-static data member + declaration. */ if (TREE_CODE (decl) == FIELD_DECL) { if (check_for_bare_parameter_packs (TREE_TYPE (decl))) @@ -3038,54 +3044,31 @@ finish_member_declaration (tree decl) A C language linkage is ignored for the names of class members and the member function type of class member functions. */ - if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c) + if (DECL_LANG_SPECIFIC (decl)) SET_DECL_LANGUAGE (decl, lang_cplusplus); - /* Put the decl on the TYPE_FIELDS list. Note that this is built up - in reverse order. We reverse it (to obtain declaration order) in - finish_struct. */ - if (DECL_DECLARES_FUNCTION_P (decl)) - { - /* We also need to add this function to the - CLASSTYPE_METHOD_VEC. */ - if (add_method (current_class_type, decl, false)) - { - gcc_assert (TYPE_MAIN_VARIANT (current_class_type) == current_class_type); - DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type); - TYPE_FIELDS (current_class_type) = decl; + bool add = false; - maybe_add_class_template_decl_list (current_class_type, decl, - /*friend_p=*/0); - } - } + /* Functions and non-functions are added differently. */ + if (DECL_DECLARES_FUNCTION_P (decl)) + add = add_method (current_class_type, decl, false); /* Enter the DECL into the scope of the class, if the class isn't a closure (whose fields are supposed to be unnamed). */ else if (CLASSTYPE_LAMBDA_EXPR (current_class_type) || pushdecl_class_level (decl)) - { - if (TREE_CODE (decl) == USING_DECL) - { - /* For now, ignore class-scope USING_DECLS, so that - debugging backends do not see them. */ - DECL_IGNORED_P (decl) = 1; - } + add = true; + if (add) + { /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields - go at the beginning. The reason is that lookup_field_1 - searches the list in order, and we want a field name to - override a type name so that the "struct stat hack" will - work. In particular: - - struct S { enum E { }; int E } s; - s.E = 3; - - is valid. In addition, the FIELD_DECLs must be maintained in - declaration order so that class layout works as expected. - However, we don't need that order until class layout, so we - save a little time by putting FIELD_DECLs on in reverse order - here, and then reversing them in finish_struct_1. (We could - also keep a pointer to the correct insertion points in the - list.) */ + go at the beginning. The reason is that + legacy_nonfn_member_lookup searches the list in order, and we + want a field name to override a type name so that the "struct + stat hack" will work. In particular: + + struct S { enum E { }; static const int E = 5; int ary[S::E]; } s; + + is valid. */ if (TREE_CODE (decl) == TYPE_DECL) TYPE_FIELDS (current_class_type)