public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105320] New: Use of shared_ptr within a type exported from a module results in spurious compiler error
@ 2022-04-20 18:28 john at johnmaddock dot co.uk
2024-03-06 21:52 ` [Bug c++/105320] " ppalka at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: john at johnmaddock dot co.uk @ 2022-04-20 18:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105320
Bug ID: 105320
Summary: Use of shared_ptr within a type exported from a module
results in spurious compiler error
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: john at johnmaddock dot co.uk
Target Milestone: ---
Reduced test case:
module.cpp:
module;
#include <memory>
export module test_support;
export template <class T> struct pimpl
{
private:
std::shared_ptr<T> data;
public:
pimpl(const T& x) : data(new T(x)) {}
pimpl() = default;
};
test_module.cpp:
import test_support;
int main()
{
pimpl<int> p1, p2(3);
}
Compile with:
g++ -std=gnu++20 -fmodules-ts module.cpp test_module.cpp
Results in:
D:/compilers/msys64/mingw64/include/c++/11.2.0/bits/shared_ptr_base.h:1369:
confused by earlier errors, bailing out
Note that there were no earlier errors ! ;)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/105320] Use of shared_ptr within a type exported from a module results in spurious compiler error
2022-04-20 18:28 [Bug c++/105320] New: Use of shared_ptr within a type exported from a module results in spurious compiler error john at johnmaddock dot co.uk
@ 2024-03-06 21:52 ` ppalka at gcc dot gnu.org
2024-03-06 21:53 ` ppalka at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-03-06 21:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105320
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-03-06
Ever confirmed|0 |1
Keywords| |rejects-valid
CC| |ppalka at gcc dot gnu.org
Status|UNCONFIRMED |NEW
--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
GCC doesn't ICE, but it rejects with:
error: conflicting declaration of template ‘template<class _Tp1,
__gnu_cxx::_Lock_policy@test_support _Lp1> class std::__shared_ptr’
note: previous declaration ‘template<class _Tp,
__gnu_cxx::_Lock_policy@test_support _Lp> class std::__shared_ptr@test_support’
error: conflicting declaration of template ‘template<class _Tp1,
__gnu_cxx::_Lock_policy@test_support _Lp1> class std::__weak_ptr’
note: previous declaration ‘template<class _Tp,
__gnu_cxx::_Lock_policy@test_support _Lp> class std::__weak_ptr@test_support’
Reduced:
$ cat 105320_a.C
module;
template<class> struct _Sp_atomic;
template<class> struct shared_ptr {
template<class> friend struct _Sp_atomic;
using atomic_type = _Sp_atomic<int>;
};
export module test_support;
export
template<class T> struct A {
shared_ptr<T> data;
};
$ cat 105320_b.C
import test_support;
A<int> a;
$ g++ -fmodules-ts 105320_{a,b}.C
105320_a.C:2:1: warning: global module fragment contents must be from
preprocessor inclusion [-Wglobal-module]
2 | template<class> struct _Sp_atomic;
| ^~~~~~~~
In module test_support, imported at 105320_b.C:1:
105320_a.C: In instantiation of ‘struct shared_ptr@test_support<int>’:
105320_a.C:11:18: required from ‘struct A@test_support<int>’
11 | shared_ptr<T> data;
| ^~~~
105320_b.C:3:8: required from here
3 | A<int> a;
| ^
105320_a.C:4:33: error: conflicting declaration of template ‘template<class>
struct _Sp_atomic’
4 | template<class> friend struct _Sp_atomic;
| ^~~~~~~~~~
105320_a.C:2:24: note: previous declaration ‘template<class> struct
_Sp_atomic@test_support’
2 | template<class> struct _Sp_atomic;
| ^~~~~~~~~~
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/105320] Use of shared_ptr within a type exported from a module results in spurious compiler error
2022-04-20 18:28 [Bug c++/105320] New: Use of shared_ptr within a type exported from a module results in spurious compiler error john at johnmaddock dot co.uk
2024-03-06 21:52 ` [Bug c++/105320] " ppalka at gcc dot gnu.org
@ 2024-03-06 21:53 ` ppalka at gcc dot gnu.org
2024-03-06 22:04 ` ppalka at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-03-06 21:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105320
--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #1)
> GCC doesn't ICE, but it rejects with:
GCC _trunk_ doesn't ICE rather..
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/105320] Use of shared_ptr within a type exported from a module results in spurious compiler error
2022-04-20 18:28 [Bug c++/105320] New: Use of shared_ptr within a type exported from a module results in spurious compiler error john at johnmaddock dot co.uk
2024-03-06 21:52 ` [Bug c++/105320] " ppalka at gcc dot gnu.org
2024-03-06 21:53 ` ppalka at gcc dot gnu.org
@ 2024-03-06 22:04 ` ppalka at gcc dot gnu.org
2024-04-30 6:23 ` cvs-commit at gcc dot gnu.org
2024-04-30 7:32 ` nshead at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-03-06 22:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105320
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |tim152 at tgf dot pw
--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 103844 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/105320] Use of shared_ptr within a type exported from a module results in spurious compiler error
2022-04-20 18:28 [Bug c++/105320] New: Use of shared_ptr within a type exported from a module results in spurious compiler error john at johnmaddock dot co.uk
` (2 preceding siblings ...)
2024-03-06 22:04 ` ppalka at gcc dot gnu.org
@ 2024-04-30 6:23 ` cvs-commit at gcc dot gnu.org
2024-04-30 7:32 ` nshead at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-30 6:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105320
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathaniel Shead <nshead@gcc.gnu.org>:
https://gcc.gnu.org/g:b5f6a56940e70838a07e885de03a92e2bd64674a
commit r15-59-gb5f6a56940e70838a07e885de03a92e2bd64674a
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date: Mon Apr 29 17:00:13 2024 +1000
c++: Fix instantiation of imported temploid friends [PR114275]
This patch fixes a number of issues with the handling of temploid friend
declarations.
The primary issue is that instantiations of friend declarations should
attach the declaration to the same module as the befriending class, by
[module.unit] p7.1 and [temp.friend] p2; this could be a different
module from the current TU, and so needs special handling.
The other main issue here is that we can't assume that just because name
lookup didn't find a definition for a hidden class template, that it
doesn't exist at all: it could be a non-exported entity that we've
nevertheless streamed in from an imported module. We need to ensure
that when instantiating template friend classes that we return the same
TEMPLATE_DECL that we got from our imports, otherwise we will get later
issues with 'duplicate_decls' (rightfully) complaining that they're
different when trying to merge.
This doesn't appear necessary for function templates due to the existing
name lookup handling already finding these hidden declarations.
PR c++/105320
PR c++/114275
gcc/cp/ChangeLog:
* cp-tree.h (propagate_defining_module): Declare.
(lookup_imported_hidden_friend): Declare.
* decl.cc (duplicate_decls): Also check if hidden decls can be
redeclared in this module.
* module.cc (imported_temploid_friends): New.
(init_modules): Initialize it.
(trees_out::decl_value): Write it; don't consider imported
temploid friends as attached to a module.
(trees_in::decl_value): Read it.
(get_originating_module_decl): Follow the owning decl for an
imported temploid friend.
(propagate_defining_module): New.
* name-lookup.cc (get_mergeable_namespace_binding): New.
(lookup_imported_hidden_friend): New.
* pt.cc (tsubst_friend_function): Propagate defining module for
new friend functions.
(tsubst_friend_class): Lookup imported hidden friends. Check
for valid module attachment of existing names. Propagate
defining module for new classes.
gcc/testsuite/ChangeLog:
* g++.dg/modules/tpl-friend-10_a.C: New test.
* g++.dg/modules/tpl-friend-10_b.C: New test.
* g++.dg/modules/tpl-friend-10_c.C: New test.
* g++.dg/modules/tpl-friend-10_d.C: New test.
* g++.dg/modules/tpl-friend-11_a.C: New test.
* g++.dg/modules/tpl-friend-11_b.C: New test.
* g++.dg/modules/tpl-friend-12_a.C: New test.
* g++.dg/modules/tpl-friend-12_b.C: New test.
* g++.dg/modules/tpl-friend-12_c.C: New test.
* g++.dg/modules/tpl-friend-12_d.C: New test.
* g++.dg/modules/tpl-friend-12_e.C: New test.
* g++.dg/modules/tpl-friend-12_f.C: New test.
* g++.dg/modules/tpl-friend-13_a.C: New test.
* g++.dg/modules/tpl-friend-13_b.C: New test.
* g++.dg/modules/tpl-friend-13_c.C: New test.
* g++.dg/modules/tpl-friend-13_d.C: New test.
* g++.dg/modules/tpl-friend-13_e.C: New test.
* g++.dg/modules/tpl-friend-13_f.C: New test.
* g++.dg/modules/tpl-friend-13_g.C: New test.
* g++.dg/modules/tpl-friend-14_a.C: New test.
* g++.dg/modules/tpl-friend-14_b.C: New test.
* g++.dg/modules/tpl-friend-14_c.C: New test.
* g++.dg/modules/tpl-friend-14_d.C: New test.
* g++.dg/modules/tpl-friend-9.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/105320] Use of shared_ptr within a type exported from a module results in spurious compiler error
2022-04-20 18:28 [Bug c++/105320] New: Use of shared_ptr within a type exported from a module results in spurious compiler error john at johnmaddock dot co.uk
` (3 preceding siblings ...)
2024-04-30 6:23 ` cvs-commit at gcc dot gnu.org
@ 2024-04-30 7:32 ` nshead at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: nshead at gcc dot gnu.org @ 2024-04-30 7:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105320
Nathaniel Shead <nshead at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |14.2
CC| |nshead at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |nshead at gcc dot gnu.org
--- Comment #5 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
Fixed for GCC 15 for now.
Will backport later to GCC 14.2 with adjustments requested by Jason here:
https://gcc.gnu.org/pipermail/gcc-patches/2024-April/650204.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-04-30 7:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-20 18:28 [Bug c++/105320] New: Use of shared_ptr within a type exported from a module results in spurious compiler error john at johnmaddock dot co.uk
2024-03-06 21:52 ` [Bug c++/105320] " ppalka at gcc dot gnu.org
2024-03-06 21:53 ` ppalka at gcc dot gnu.org
2024-03-06 22:04 ` ppalka at gcc dot gnu.org
2024-04-30 6:23 ` cvs-commit at gcc dot gnu.org
2024-04-30 7:32 ` nshead at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).