From patchwork Fri Apr 2 16:07:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1461785 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=D9ei2aRK; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FBlMH2nrnz9sTD for ; Sat, 3 Apr 2021 03:07:54 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 79ADA385801D; Fri, 2 Apr 2021 16:07:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by sourceware.org (Postfix) with ESMTPS id E1D973858D33 for ; Fri, 2 Apr 2021 16:07:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E1D973858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qk1-x72b.google.com with SMTP id y5so5641160qkl.9 for ; Fri, 02 Apr 2021 09:07:47 -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=SCyPOXv/ULoPqY3FkeZ7RDUmVC8gH45dKvZjoFgFqEI=; b=D9ei2aRKeilPkbVOYpURWOKGDPXKpNJvkGA6hNnie+QuPr1tYgmGJmanxIkO8+PK0y 07SrPS8TYAAc3/woCwWG5xZLCYUvTretwGMcMNtsRqLC9y7/6+7MxAl6O0FJ85A0d3Zd QW49cNZSYpWLqkZ4LJuFI/H4LBefW+Bwd9iouC5Q8+fNqUrD2wpErukGDvFjOikZCOiV ncylp06EklLgD+2SswmP3V7OpZ8UExYu2V9wmMk9qCWDYljFjrMyNDUHortNyvHEPlTb +NTuw0mluIIDFIskCLB457LniR0AZAdO5fFtUBqXW0V7QjQfJw61HtfMG70t+Nixhpuj ZTvQ== 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=SCyPOXv/ULoPqY3FkeZ7RDUmVC8gH45dKvZjoFgFqEI=; b=O9UgW45hwZp7eEjHeyA8oZbJkeR/hNdOGwnDcDIbCoZT7vuJf+WARFokKSJyknWwgL 6iJlkRNe4rkYVfvdLCoyIi+byFGqjCk/PzE7YZh+DVQKhwBeUaaZPjqHprvNnh1W/o8r CJ8kto5+xLG2Z07PKwQeFfPypK1SaQP3McQelLBPhO3G2+mak1+wUQlur6CkMXfw5yvx v5EhN2kTpQV6QeASazHTXMdibBW4ij3iJt8NNWTbpQeAXi0sEZ3paTV+gs4EKk1b+uTv +ibrJdu6qsbDiRVkYVcjBNHwaIAHgSwl1Hj52CPObGQAt2oL2JlVnle7P2H0EGUm5d8v TD0g== X-Gm-Message-State: AOAM531UkqSJVmuhJS97py8ZIGANnPAMXaPSY/7x/0mBzbN3/gkCzlhI 6OujKSwnM8b/1RGhWNIv6u0= X-Google-Smtp-Source: ABdhPJytHN+VZZKOCkU7WTCZfYOJ3LXPGnKFdyrqYsg7yX/s1cuTV7KEyZI8PuRIRGnaUDnpovhlGA== X-Received: by 2002:a37:9f89:: with SMTP id i131mr14260217qke.160.1617379667532; Fri, 02 Apr 2021 09:07:47 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:66fa:699b:3f0e:e46f? ([2620:10d:c091:480::1:c79]) by smtp.googlemail.com with ESMTPSA id n24sm6834823qtr.21.2021.04.02.09.07.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 02 Apr 2021 09:07:46 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: c++: header unit purview [PR 99283] Message-ID: Date: Fri, 2 Apr 2021 12:07:45 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-3039.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This case occurs due to some equivocation about module_purview. Header-unit building is treated as a module-purview, but we should not treat entities imported from that as module purview. (header units were not a thing when I started). The testcase didn't understand we had a local textual definition, but it was (incorrectly) marked as module-purview, because we'd read in a declaration from a header unit too. gcc/cp/ * cp-tree.h (lang_decl_base): Correct module flag comment. * gcc/cp/module.cc (trees_in::assert_definition): Break out not_tmpl var. (trees_out::lang_decl_bools): Do not write purview for header units. gcc/testsuite/ * g++.dg/modules/pr99283-6_d.H: New. * g++.dg/modules/pr99283-7-swap.h: New. * g++.dg/modules/pr99283-7-traits.h: New. * g++.dg/modules/pr99283-7_a.H: New. * g++.dg/modules/pr99283-7_b.H: New. * g++.dg/modules/pr99283-7_c.C: New. * g++.dg/modules/pr99283-7_d.H: New. diff --git c/gcc/cp/cp-tree.h w/gcc/cp/cp-tree.h index 9535910fd4e..66bba7b4d43 100644 --- c/gcc/cp/cp-tree.h +++ w/gcc/cp/cp-tree.h @@ -2756,8 +2756,8 @@ struct GTY(()) lang_decl_base { unsigned var_declared_inline_p : 1; /* var */ unsigned dependent_init_p : 1; /* var */ - /* The following apply to VAR, FUNCTION, TYPE, CONCEPT, TEMPLATE, - NAMESPACE decls. */ + /* The following apply to VAR, FUNCTION, TYPE, CONCEPT, & NAMESPACE + decls. */ unsigned module_purview_p : 1; /* in module purview (not GMF) */ unsigned module_import_p : 1; /* from an import */ unsigned module_entity_p : 1; /* is in the entitity ary & diff --git c/gcc/cp/module.cc w/gcc/cp/module.cc index c87ddd16a80..d5b7d28ded5 100644 --- c/gcc/cp/module.cc +++ w/gcc/cp/module.cc @@ -4477,6 +4477,7 @@ trees_in::assert_definition (tree decl ATTRIBUTE_UNUSED, { #if CHECKING_P tree *slot = note_defs->find_slot (decl, installing ? INSERT : NO_INSERT); + tree not_tmpl = STRIP_TEMPLATE (decl); if (installing) { /* We must be inserting for the first time. */ @@ -4492,13 +4493,13 @@ trees_in::assert_definition (tree decl ATTRIBUTE_UNUSED, gcc_assert (!is_duplicate (decl) ? !slot : (slot - || !DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl)) - || !DECL_MODULE_PURVIEW_P (STRIP_TEMPLATE (decl)) - || (!DECL_MODULE_IMPORT_P (STRIP_TEMPLATE (decl)) + || !DECL_LANG_SPECIFIC (not_tmpl) + || !DECL_MODULE_PURVIEW_P (not_tmpl) + || (!DECL_MODULE_IMPORT_P (not_tmpl) && header_module_p ()))); - if (TREE_CODE (decl) == TEMPLATE_DECL) - gcc_assert (!note_defs->find_slot (DECL_TEMPLATE_RESULT (decl), NO_INSERT)); + if (not_tmpl != decl) + gcc_assert (!note_defs->find_slot (not_tmpl, NO_INSERT)); #endif } @@ -5519,7 +5520,9 @@ trees_out::lang_decl_bools (tree t) WB (lang->u.base.concept_p); WB (lang->u.base.var_declared_inline_p); WB (lang->u.base.dependent_init_p); - WB (lang->u.base.module_purview_p); + /* When building a header unit, everthing is marked as purview, but + that's the GM purview, so not what the importer will mean */ + WB (lang->u.base.module_purview_p && !header_module_p ()); if (VAR_OR_FUNCTION_DECL_P (t)) WB (lang->u.base.module_attached_p); switch (lang->u.base.selector) @@ -11304,7 +11307,7 @@ trees_in::register_duplicate (tree decl, tree existing) /* We've read a definition of MAYBE_EXISTING. If not a duplicate, return MAYBE_EXISTING (into which the definition should be installed). Otherwise return NULL if already known bad, or the - duplicate we read (for ODR checking, or extracting addtional merge + duplicate we read (for ODR checking, or extracting additional merge information). */ tree diff --git c/gcc/testsuite/g++.dg/modules/pr99283-6_d.H w/gcc/testsuite/g++.dg/modules/pr99283-6_d.H new file mode 100644 index 00000000000..e8114711f38 --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr99283-6_d.H @@ -0,0 +1,10 @@ +// { dg-additional-options {-std=c++2a -fmodule-header} } + +import "pr99283-6_b.H"; + +template +struct __allocated_ptr +{ + using value_type = allocator_traits<_Alloc>; +}; + diff --git c/gcc/testsuite/g++.dg/modules/pr99283-7-swap.h w/gcc/testsuite/g++.dg/modules/pr99283-7-swap.h new file mode 100644 index 00000000000..d725fea9ee5 --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr99283-7-swap.h @@ -0,0 +1,17 @@ +template +constexpr typename remove_reference<_Tp>::type&& + move(_Tp&& __t) noexcept; + +template +constexpr inline +typename enable_if<__and_<__not_<__is_tuple_like<_Tp>>, + is_move_constructible<_Tp>, + is_move_assignable<_Tp>>::value>::type + swap(_Tp& __a, _Tp& __b) + noexcept(__and_, + is_nothrow_move_assignable<_Tp>>::value) +{ + _Tp __tmp = move(__a); + __a = move(__b); + __b = move(__tmp); +} diff --git c/gcc/testsuite/g++.dg/modules/pr99283-7-traits.h w/gcc/testsuite/g++.dg/modules/pr99283-7-traits.h new file mode 100644 index 00000000000..8f6bce04bee --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr99283-7-traits.h @@ -0,0 +1,41 @@ +template +struct __and_; + +template +struct __not_; + +template +struct is_move_constructible; + +template +struct is_nothrow_move_constructible; + +template +struct is_move_assignable; + +template +struct is_nothrow_move_assignable; + +template +struct remove_reference; + +template +struct enable_if; + +template +using __enable_if_t = typename enable_if<_Cond, _Tp>::type; + +template +using _Require = __enable_if_t<__and_<_Cond...>::value>; + +template +struct __is_tuple_like; + +template +constexpr inline + _Require<__not_<__is_tuple_like<_Tp>>, + is_move_constructible<_Tp>, + is_move_assignable<_Tp>> +swap(_Tp&, _Tp&) + noexcept(__and_, + is_nothrow_move_assignable<_Tp>>::value); diff --git c/gcc/testsuite/g++.dg/modules/pr99283-7_a.H w/gcc/testsuite/g++.dg/modules/pr99283-7_a.H new file mode 100644 index 00000000000..b52d44d5c26 --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr99283-7_a.H @@ -0,0 +1,97 @@ +// PR 99283, +// { dg-additional-options "-std=c++2a -fmodule-header" } +// { dg-module-cmi {} } + +#include "pr99283-7-traits.h" + +template +struct char_traits; + +template> +class basic_string; + +typedef basic_string string; + +template +struct integral_constant +{ + static constexpr _Tp value = __v; + typedef _Tp value_type; + typedef integral_constant<_Tp, __v> type; + constexpr operator value_type() const noexcept { return value; } + constexpr value_type operator()() const noexcept { return value; } +}; + +template +constexpr _Tp integral_constant<_Tp, __v>::value; + +typedef integral_constant true_type; + +typedef integral_constant false_type; + +template +using __bool_constant = integral_constant; + +template +_Up __declval(int); + +template +_Tp __declval(long); + +template +auto declval() noexcept -> decltype(__declval<_Tp>(0)); + +struct __do_is_nothrow_swappable_impl +{ + template + static __bool_constant< + noexcept(swap(declval<_Tp&>(), declval<_Tp&>())) + > __test(int); +}; + + + +template +struct __is_nothrow_swappable_impl + : public __do_is_nothrow_swappable_impl +{ + typedef decltype(__test<_Tp>(0)) type; +}; + +template +struct __is_nothrow_swappable + : public __is_nothrow_swappable_impl<_Tp>::type +{ }; + +#include "pr99283-7-swap.h" + +class partial_ordering +{ +public: + friend constexpr bool + operator==(partial_ordering, partial_ordering) noexcept = default; +}; + +class strong_ordering +{ +public: + constexpr operator partial_ordering() const noexcept; +}; + +template +struct pair +{ + constexpr void + swap(pair& __p) + noexcept(__is_nothrow_swappable<_T1>::value); +}; + +template +inline constexpr bool + operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y); + +template +struct char_traits +{ + using comparison_category = strong_ordering; +}; diff --git c/gcc/testsuite/g++.dg/modules/pr99283-7_b.H w/gcc/testsuite/g++.dg/modules/pr99283-7_b.H new file mode 100644 index 00000000000..50c780e096e --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr99283-7_b.H @@ -0,0 +1,4 @@ +// { dg-additional-options "-std=c++2a -fmodule-header" } +// { dg-module-cmi {} } + +#include "pr99283-7-traits.h" diff --git c/gcc/testsuite/g++.dg/modules/pr99283-7_c.C w/gcc/testsuite/g++.dg/modules/pr99283-7_c.C new file mode 100644 index 00000000000..195bc684e40 --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr99283-7_c.C @@ -0,0 +1,8 @@ +// { dg-additional-options "-std=c++2a -fmodules-ts" } +import "pr99283-7_b.H"; + +#include "pr99283-7-swap.h" + +import "pr99283-7_a.H"; + +void Xlocale(const string& __s); diff --git c/gcc/testsuite/g++.dg/modules/pr99283-7_d.H w/gcc/testsuite/g++.dg/modules/pr99283-7_d.H new file mode 100644 index 00000000000..ef4934beac0 --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr99283-7_d.H @@ -0,0 +1,8 @@ +// { dg-additional-options "-std=c++2a -fmodule-header" } +import "pr99283-7_b.H"; + +#include "pr99283-7-swap.h" + +import "pr99283-7_a.H"; + +void Xlocale(const string& __s);