diff options
author | Jason Merrill <jason@redhat.com> | 2024-06-12 18:24:35 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2024-06-13 11:06:14 -0400 |
commit | 609764a42f0cd3f6358562cab98fc220d3d2d9fd (patch) | |
tree | d50115a8cdb61df9d3046b9de7bc690d23309d96 /gcc | |
parent | 8878fecc251762bc32c24e659695557797e03fd9 (diff) | |
download | gcc-609764a42f0cd3f6358562cab98fc220d3d2d9fd.zip gcc-609764a42f0cd3f6358562cab98fc220d3d2d9fd.tar.gz gcc-609764a42f0cd3f6358562cab98fc220d3d2d9fd.tar.bz2 |
c++/modules: export using across namespace [PR114683]
Currently we represent a non-function using-declaration by inserting the
named declaration into the target scope. In general this works fine, but in
the case of an exported using-declaration we have nowhere to mark the
using-declaration as exported, so we mark the original declaration as
exported instead, and then treat all using-declarations that name it as
exported as well. We were doing this only if there was also a previous
non-exported using, so for this testcase the export got lost; this patch
broadens the workaround to also apply to the using that first brings the
declaration into the current scope.
This does not fully resolve 114683, but replaces a missing exports bug with
an extra exports bug, which should be a significant usability improvement.
The testcase has xfails for extra exports.
I imagine a complete fix should involve inserting a USING_DECL.
PR c++/114683
gcc/cp/ChangeLog:
* name-lookup.cc (do_nonmember_using_decl): Allow exporting
a newly inserted decl.
gcc/testsuite/ChangeLog:
* g++.dg/modules/using-22_a.C: New test.
* g++.dg/modules/using-22_b.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/name-lookup.cc | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/modules/using-22_a.C | 24 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/modules/using-22_b.C | 13 |
3 files changed, 39 insertions, 3 deletions
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index 71482db..b578931 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -5316,14 +5316,13 @@ do_nonmember_using_decl (name_lookup &lookup, bool fn_scope_p, /* FIXME: Handle exporting declarations from a different scope without also marking those declarations as exported. This will require not just binding directly to the underlying - value; see c++/114863 and c++/114865. We allow this for purview - declarations for now as this doesn't (currently) cause ICEs + value; see c++/114683 and c++/114685. We allow the extra exports + for now as this doesn't (currently) cause ICEs later down the line, but this should be revisited. */ if (revealing_p) { if (module_exporting_p () && check_can_export_using_decl (lookup.value) - && lookup.value == value && !DECL_MODULE_EXPORT_P (lookup.value)) { /* We're redeclaring the same value, but this time as diff --git a/gcc/testsuite/g++.dg/modules/using-22_a.C b/gcc/testsuite/g++.dg/modules/using-22_a.C new file mode 100644 index 0000000..9eca9da --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/using-22_a.C @@ -0,0 +1,24 @@ +// PR c++/114683 +// { dg-additional-options "-fmodules-ts -Wno-global-module" } + +module; + +namespace std +{ + inline namespace __cxx11 + { + template <typename T> + struct basic_string{}; + } +} + +namespace foo { + using std::basic_string; +} + +export module std; + +export namespace std +{ + using std::basic_string; +} diff --git a/gcc/testsuite/g++.dg/modules/using-22_b.C b/gcc/testsuite/g++.dg/modules/using-22_b.C new file mode 100644 index 0000000..0b66f4a --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/using-22_b.C @@ -0,0 +1,13 @@ +// { dg-additional-options "-fmodules-ts" } + +import std; + +int main() +{ + std::basic_string<char> s; + + // The inline namespace should not be exported, only the 'using' in std. + std::__cxx11::basic_string<char> s2; // { dg-error "has not been declared" "" { xfail *-*-* } } + // The non-exported using should also not be visible. + foo::basic_string<char> s3; // { dg-error "has not been declared" "" { xfail *-*-* } } +} |