From patchwork Mon May 20 12:45:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1101970 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-501192-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="mqO9yUWc"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="kDCUMDZn"; 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 456zCm58Kqz9sSr for ; Mon, 20 May 2019 22:46:10 +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=ldEAH/ywX7FW+UCuPCgYYy9pAEyf6qJk6nvaNA5S8I5LPoronm Aq07M5ggjD5Ew2Zpj7YVOVM7ZETq3r4PSoZAHebZrVUCVlbYm7d3UyCtlqk/Z72e Xp0XwuBlsK5fCiq2SBLq/iDS3eDCa4/SMgDoU4pmwj1KQn/Rvx2guPTQo= 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=bKA6Iwp5qU5Ii1/VdWyk++ca1SQ=; b=mqO9yUWc+Aw2KOhn+/a4 VjyjXKUew6qiYVkAoZszkkVZsFPkcTe75OQ7SGwSNxJHGgJue/0p9FBn3himEGh+ EscRfphB3HKlNA86T0mSBemc9mvG+Y2Oiyq6s3CvM3jZIy8JdmYq7B7TKpbDSEzT xD98aMg8PF6Hrp37ppqYtsg= Received: (qmail 17588 invoked by alias); 20 May 2019 12:46:04 -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 17579 invoked by uid 89); 20 May 2019 12:46:03 -0000 Authentication-Results: sourceware.org; auth=none 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.1 spammy=H*r:sk:mail-pg, HX-Spam-Relays-External:sk:mail-pg, HX-HELO:sk:mail-pg, HX-Received:aa7 X-HELO: mail-pg1-f180.google.com Received: from mail-pg1-f180.google.com (HELO mail-pg1-f180.google.com) (209.85.215.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 May 2019 12:46:02 +0000 Received: by mail-pg1-f180.google.com with SMTP id t1so5343127pgc.2 for ; Mon, 20 May 2019 05:46:01 -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=bU010T8ZzzoY0FgNHiQ7Vx9ziwku5ctmWmaE6JAoOQc=; b=kDCUMDZnLXu2nJqIytqVtUqCYU5a0gSiFcTsEBVwcTXfW/H+0wLfpeeRfwCsm1vpKM 9a3tJw4R9YdRkDLpxx7ywjVFptPEia+DgwXJJEG9dv0q9bCramdYwFZoYxi9L9EFaQCN 26BT4+VNkszy2jQSJZQK9QkGN8kcNLwt3ZdZfe4GneGAe9s5omj7n1+hYcM4fRGgJ7tz R/b9LMXotbgNQ7NQwW0bCaLNjHcwA9yAOMo/1MecHagXxdTJbsZZHuAb6WD7XTNUhoF4 Sbq41A/Bnpamvg5BS+uW6aySdNnGjPa1LUz+bGaarxMk36GS5j43ohXlmTSJH1jDtPDh br6w== Received: from ?IPv6:2620:10d:c0a3:1407:6077:ec57:6cfa:c95c? ([2620:10d:c091:500::3:8245]) by smtp.googlemail.com with ESMTPSA id h14sm20338762pgj.8.2019.05.20.05.45.58 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Mon, 20 May 2019 05:45:59 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] namespace using directives Message-ID: Date: Mon, 20 May 2019 08:45:57 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 A patch from the modules branch. I realized we don't need namespace field to hold using directives. Each binding level already has such a field, and we can easily go from namespace decl to its binding level. This patch removes the usings field, and adjusts the accesses in name-lookup. As another benefit the diagnostic machinery looking for using namespace std is simplified. Applying to trunk. nathan 2019-05-20 Nathan Sidwell * cp-tree.h (struct lang_decl_ns): Remove usings field. (DECL_NAMESPACE_USING): Delete. * name-lookup.c (name_lookup::search_usings): Use namespace's binding scope. (name_lookup::queue_namespae): Likewise. (finish_namespace_using_directive, push_namespace): Likewise. (has_using_namespace_std_directive): Just search the entire binding stack. Index: gcc/cp/cp-tree.h =================================================================== --- gcc/cp/cp-tree.h (revision 271412) +++ gcc/cp/cp-tree.h (working copy) @@ -2669,7 +2669,5 @@ struct GTY(()) lang_decl_ns { cp_binding_level *level; - /* using directives and inline children. These need to be va_gc, - because of PCH. */ - vec *usings; + /* Inline children. These need to be va_gc, because of PCH. */ vec *inlinees; @@ -3260,8 +3258,4 @@ struct GTY(()) lang_decl { TREE_LANG_FLAG_0 (NAMESPACE_DECL_CHECK (NODE)) -/* In a NAMESPACE_DECL, a vector of using directives. */ -#define DECL_NAMESPACE_USING(NODE) \ - (LANG_DECL_NS_CHECK (NODE)->usings) - /* In a NAMESPACE_DECL, a vector of inline namespaces. */ #define DECL_NAMESPACE_INLINEES(NODE) \ Index: gcc/cp/name-lookup.c =================================================================== --- gcc/cp/name-lookup.c (revision 271412) +++ gcc/cp/name-lookup.c (working copy) @@ -590,5 +590,5 @@ name_lookup::search_usings (tree scope) bool found = false; - if (vec *usings = DECL_NAMESPACE_USING (scope)) + if (vec *usings = NAMESPACE_LEVEL (scope)->using_directives) for (unsigned ix = usings->length (); ix--;) found |= search_qualified ((*usings)[ix], true); @@ -652,5 +652,5 @@ name_lookup::queue_namespace (using_queu /* Queue its using targets. */ - queue = queue_usings (queue, depth, DECL_NAMESPACE_USING (scope)); + queue = queue_usings (queue, depth, NAMESPACE_LEVEL (scope)->using_directives); return queue; @@ -5273,19 +5273,9 @@ has_using_namespace_std_directive_p () /* Look at local using-directives. */ for (cp_binding_level *level = current_binding_level; - level->kind != sk_namespace; + level; level = level->level_chain) if (using_directives_contain_std_p (level->using_directives)) return true; - /* Look at this namespace and its ancestors. */ - for (tree scope = current_namespace; scope; scope = CP_DECL_CONTEXT (scope)) - { - if (using_directives_contain_std_p (DECL_NAMESPACE_USING (scope))) - return true; - - if (scope == global_namespace) - break; - } - return false; } @@ -7254,5 +7244,5 @@ finish_namespace_using_directive (tree t return; - add_using_namespace (DECL_NAMESPACE_USING (current_namespace), + add_using_namespace (current_binding_level->using_directives, ORIGINAL_NAMESPACE (target)); emit_debug_info_using_namespace (current_namespace, @@ -7405,5 +7395,5 @@ push_namespace (tree name, bool make_inl if (!make_inline) - add_using_namespace (DECL_NAMESPACE_USING (current_namespace), + add_using_namespace (current_binding_level->using_directives, ns); }