Skip to content

Commit cb6c7c6

Browse files
committed
Merge pull request #107379 from Ivorforce/callable-signal-explicit-string
Core: Remove implicit conversions from `Callable` and `Signal` to `String`, to avoid accidental conversions
2 parents 067721b + d2f9d31 commit cb6c7c6

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

core/string/translation_server.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class TranslationServer : public Object {
7777
(p_locale.variant == variant);
7878
}
7979

80-
operator String() const;
80+
explicit operator String() const;
8181

8282
Locale(const TranslationServer &p_server, const String &p_locale, bool p_add_defaults);
8383
};

core/templates/hashfuncs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "core/templates/pair.h"
5656
#include "core/templates/rid.h"
5757
#include "core/typedefs.h"
58+
#include "core/variant/callable.h"
5859

5960
#ifdef _MSC_VER
6061
#include <intrin.h> // Needed for `__umulh` below.
@@ -342,6 +343,7 @@ struct HashMapHasherDefault {
342343
static _FORCE_INLINE_ uint32_t hash(const StringName &p_string_name) { return p_string_name.hash(); }
343344
static _FORCE_INLINE_ uint32_t hash(const NodePath &p_path) { return p_path.hash(); }
344345
static _FORCE_INLINE_ uint32_t hash(const ObjectID &p_id) { return hash_one_uint64(p_id); }
346+
static _FORCE_INLINE_ uint32_t hash(const Callable &p_callable) { return p_callable.hash(); }
345347

346348
static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); }
347349
static _FORCE_INLINE_ uint32_t hash(const int64_t p_int) { return hash_one_uint64(uint64_t(p_int)); }

core/variant/callable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class Callable {
123123

124124
void operator=(const Callable &p_callable);
125125

126-
operator String() const;
126+
explicit operator String() const;
127127

128128
static Callable create(const Variant &p_variant, const StringName &p_method);
129129

@@ -190,7 +190,7 @@ class Signal {
190190
bool operator!=(const Signal &p_signal) const;
191191
bool operator<(const Signal &p_signal) const;
192192

193-
operator String() const;
193+
explicit operator String() const;
194194

195195
Error emit(const Variant **p_arguments, int p_argcount) const;
196196
Error connect(const Callable &p_callable, uint32_t p_flags = 0);

core/variant/method_ptrcall.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ struct PtrToArgStringConvertByReference {
131131
// No EncodeT because direct pointer conversion not possible.
132132
_FORCE_INLINE_ static void encode(const T &p_vec, void *p_ptr) {
133133
String *arr = reinterpret_cast<String *>(p_ptr);
134-
*arr = p_vec;
134+
*arr = String(p_vec);
135135
}
136136
};
137137

core/variant/variant.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,11 +1725,11 @@ String Variant::stringify(int recursion_count) const {
17251725
}
17261726
case CALLABLE: {
17271727
const Callable &c = *reinterpret_cast<const Callable *>(_data._mem);
1728-
return c;
1728+
return String(c);
17291729
}
17301730
case SIGNAL: {
17311731
const Signal &s = *reinterpret_cast<const Signal *>(_data._mem);
1732-
return s;
1732+
return String(s);
17331733
}
17341734
case RID: {
17351735
const ::RID &s = *reinterpret_cast<const ::RID *>(_data._mem);

0 commit comments

Comments
 (0)