mirrored from git://gcc.gnu.org/git/gcc.git
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c++/modules: imported spec befriending class tmpl [PR114889]
When adding to CLASSTYPE_BEFRIENDING_CLASSES as part of installing an imported class definition, we need to look through TEMPLATE_DECL like make_friend_class does. Otherwise in the below testcase we won't add _Hashtable<int, int> to CLASSTYPE_BEFRIENDING_CLASSES of _Map_base, which leads to a bogus access check failure for _M_hash_code. PR c++/114889 gcc/cp/ChangeLog: * module.cc (trees_in::read_class_def): Look through TEMPLATE_DECL when adding to CLASSTYPE_BEFRIENDING_CLASSES. gcc/testsuite/ChangeLog: * g++.dg/modules/friend-8_a.H: New test. * g++.dg/modules/friend-8_b.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
- Loading branch information
Patrick Palka
committed
Apr 30, 2024
1 parent
3900e94
commit 22b20ac
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// PR c++/114889 | ||
// { dg-additional-options "-fmodule-header" } | ||
// { dg-module-cmi {} } | ||
|
||
template<class, class> | ||
struct _Hashtable; | ||
|
||
template<class _Key, class _Val> | ||
struct _Map_base { | ||
void f() { | ||
_Hashtable<_Key, _Val> __h; | ||
__h._M_hash_code(0); | ||
} | ||
}; | ||
|
||
template<class _Key, class _Value> | ||
struct _Hashtable { | ||
template<class, class> friend struct _Map_base; | ||
protected: | ||
void _M_hash_code(int); | ||
}; | ||
|
||
inline _Hashtable<int, int> m; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// PR c++/114889 | ||
// { dg-additional-options "-fmodules-ts" } | ||
|
||
import "friend-8_a.H"; | ||
|
||
int main() { | ||
_Map_base<int, int> m; | ||
m.f(); | ||
} |