diff options
author | Patrick Palka <ppalka@redhat.com> | 2022-10-11 15:02:23 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2022-10-11 15:02:23 -0400 |
commit | 9736a42e1fb8df30d72cf28594d9046bf50200c1 (patch) | |
tree | 479a0ee754f228f76d48a4adb13d3e96fadb28a9 /gcc/cp/cp-lang.cc | |
parent | 2ceb4d531a303f3e70d8bb218c8759e6c0688f62 (diff) | |
download | gcc-9736a42e1fb8df30d72cf28594d9046bf50200c1.zip gcc-9736a42e1fb8df30d72cf28594d9046bf50200c1.tar.gz gcc-9736a42e1fb8df30d72cf28594d9046bf50200c1.tar.bz2 |
c++ modules: ICE with templated friend and std namespace [PR100134]
The function depset::hash::add_binding_entity has an assert verifying
that if a namespace contains an exported entity, then the namespace must
have been opened in the module purview:
if (data->hash->add_namespace_entities (decl, data->partitions))
{
/* It contains an exported thing, so it is exported. */
gcc_checking_assert (DECL_MODULE_PURVIEW_P (decl));
DECL_MODULE_EXPORT_P (decl) = true;
}
We're tripping over this assert in the below testcase because by
instantiating and exporting std::A<int>, we in turn define and export the
hidden friend std::f(A<int>) without ever having opened the enclosing
namespace std within the module purview, and thus DECL_MODULE_PURVIEW_P
for std is false.
It's important that the enclosing namespace is std here: if we use
a different namespace then the ICE disappears. This probably has
something to do with us predefining std via push_namespace from
cxx_init_decl_processing (which makes it look like we've opened it
within the TU), whereas with another namespace we would instead lazily
create its NAMESPACE_DECL from add_imported_namespace.
Since templated friend functions are special in that they give us a way
to introduce a namespace-scope function without having to explicitly
open the namespace, this patch proposes to fix this ICE by propagating
DECL_MODULE_PURVIEW_P from the introduced function to the enclosing
namespace during tsubst_friend_function.
PR c++/100134
gcc/cp/ChangeLog:
* pt.cc (tsubst_friend_function): Propagate DECL_MODULE_PURVIEW_P
from the introduced namespace-scope function to the namespace.
gcc/testsuite/ChangeLog:
* g++.dg/modules/tpl-friend-8_a.H: New test.
* g++.dg/modules/tpl-friend-8_b.C: New test.
Diffstat (limited to 'gcc/cp/cp-lang.cc')
0 files changed, 0 insertions, 0 deletions