[PATCH 2/2] modules: c++: Fix cross module member redecl/add long distance friendship warning

Jeff Chapman jchapman@lock3software.com
Fri Aug 14 15:19:53 GMT 2020


Attached is a patch adding a -Wlong-distance-friends flag to diagnose long
distance (cross module) friendship.


2020-08-14  Jeff Chapman II  <jchapman@lock3software.com>

gcc/c-family/
	* c.opt (Wlong-distance-friends): New.

gcc/cp/
	* cp-tree.h (module_friendship_compatible): New.
	* friend.c (add_friend): Warn when befriending a function owned
	by a different module.
	(make_friend_class): Warn when befriending a class owned by a
	different module.
	* module.cc (module_friendship_compatible): New function.
	Returns true if a decl may be befriended by another without
	issuing a long distance friend warning.

gcc/testsuite/
	* g++.dg/modules/long-distance-friend-1_[ab].C: New test.
	* g++.dg/modules/long-distance-friend-2_a.[Ch]: Ditto.
	* g++.dg/modules/long-distance-friend-3_[ab].[Ch]: Ditto.
	* g++.dg/modules/redecl-3_b.C: Add case for -Wlong-distance-friends.


Thanks,
Jeff Chapman II
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-c-Add-warning-flag-for-cross-module-friendship.patch
Type: text/x-patch
Size: 11600 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200814/3e2ce395/attachment-0001.bin>


More information about the Gcc-patches mailing list