[PATCH RFA] libstdc++: add ADL friends

Jason Merrill jason@redhat.com
Sun Nov 2 19:01:47 GMT 2025


Tested x86_64-pc-linux-gnu, OK for trunk?

-- 8< --

Since the implementation namespaces __detail and __exception_ptr aren't
exported from std, ADL can't find these functions there.  Adding friend
declarations makes it work.

libstdc++-v3/ChangeLog:

	* include/bits/quoted_string.h: Add ADL friends.
	* libsupc++/exception_ptr.h: Add ADL friend.
---
 libstdc++-v3/include/bits/quoted_string.h | 23 +++++++++++++++++++++++
 libstdc++-v3/libsupc++/exception_ptr.h    |  4 ++++
 2 files changed, 27 insertions(+)

diff --git a/libstdc++-v3/include/bits/quoted_string.h b/libstdc++-v3/include/bits/quoted_string.h
index 3a828d5eab9..9a51aa367fe 100644
--- a/libstdc++-v3/include/bits/quoted_string.h
+++ b/libstdc++-v3/include/bits/quoted_string.h
@@ -61,6 +61,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	_Quoted_string&
 	operator=(_Quoted_string&) = delete;
 
+	// Friends for ADL with module std.
+	template<typename _CharT2, typename _Traits>
+	friend std::basic_ostream<_CharT2, _Traits>&
+	operator<<(std::basic_ostream<_CharT2, _Traits>& __os,
+		   const _Quoted_string<const _CharT2*, _CharT2>& __str);
+
+	template<typename _CharT2, typename _Traits, typename _String2>
+	friend std::basic_ostream<_CharT2, _Traits>&
+	operator<<(std::basic_ostream<_CharT2, _Traits>& __os,
+		   const _Quoted_string<_String2, _CharT2>& __str);
+
+	template<typename _CharT2, typename _Traits, typename _Alloc>
+	friend std::basic_istream<_CharT2, _Traits>&
+	operator>>(std::basic_istream<_CharT2, _Traits>& __is,
+		   const _Quoted_string<basic_string<_CharT2, _Traits, _Alloc>&,
+		   _CharT2>& __str);
+
 	_String _M_string;
 	_CharT _M_delim;
 	_CharT _M_escape;
@@ -78,6 +95,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	_Quoted_string&
 	operator=(_Quoted_string&) = delete;
 
+	// Friend for ADL with module std.
+	template<typename _CharT2, typename _Traits2, typename _String2>
+	friend std::basic_ostream<_CharT2, _Traits2>&
+	operator<<(std::basic_ostream<_CharT2, _Traits2>& __os,
+		   const _Quoted_string<_String2, _CharT2>& __str);
+
 	basic_string_view<_CharT, _Traits> _M_string;
 	_CharT _M_delim;
 	_CharT _M_escape;
diff --git a/libstdc++-v3/libsupc++/exception_ptr.h b/libstdc++-v3/libsupc++/exception_ptr.h
index f673a334333..76482db3756 100644
--- a/libstdc++-v3/libsupc++/exception_ptr.h
+++ b/libstdc++-v3/libsupc++/exception_ptr.h
@@ -214,6 +214,10 @@ namespace std _GLIBCXX_VISIBILITY(default)
       { return __x._M_exception_object != __y._M_exception_object; }
 #endif
 
+      // Friend for ADL with module std.
+      friend _GLIBCXX26_CONSTEXPR void
+      swap(exception_ptr& __lhs, exception_ptr& __rhs);
+
       const class std::type_info*
       __cxa_exception_type() const _GLIBCXX_USE_NOEXCEPT
 	__attribute__ ((__pure__));

base-commit: 2be505ace7e5e29a29ab53025762cf1a100a6d76
-- 
2.51.0



More information about the Libstdc++ mailing list