1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
From ce6d4c9a3bb8a7b7c00447d56c16e0975705f2a2 Mon Sep 17 00:00:00 2001
From: Mark Nauwelaerts <mnauw@users.sourceforge.net>
Date: Sun, 17 Dec 2023 23:44:13 +0100
Subject: [PATCH] gi: restrict string template conversion operator
See issue #65
---
gi/string.hpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/gi/string.hpp b/gi/string.hpp
index 3621b50..55b7926 100644
--- a/gi/string.hpp
+++ b/gi/string.hpp
@@ -749,10 +749,17 @@ struct converter<From, detail::cstr<transfer_full_t>,
// to a typical string(_view) case
// (avoid conflict with above)
+// the traits_type (tries to) restricts this to std::string(_view)
+// not doing so might conveniently allow conversion to other types as well.
+// however, this would also allow e.g. QByteArray, which comes with an operator+
+// in global namespace (also selected by non-ADL lookup),
+// which then results in ambiguous overload
+// (with the operator+ that is provided above)
template<typename Transfer, typename To>
struct converter<detail::cstr<Transfer>, To,
typename std::enable_if<
!std::is_base_of<detail::String, To>::value &&
+ !std::is_same<typename To::traits_type, void>::value &&
std::is_constructible<To, const char *, size_t>::value>::type>
: public converter_base<detail::cstr<Transfer>, To>
{
--
GitLab
|