Don't return reference on copy assignment operators

We prefer to prevent using chained assignment (`T a = b = c = T();`) as this
can lead to confusing code and subtle bugs.

According to https://en.wikipedia.org/wiki/Assignment_operator_(C%2B%2B), C++
allows any arbitrary return type, so this is standard compliant.

This could be re-assessed if/when we have an actual need for a behavior more
akin to that of the C++ STL, for now this PR simply changes a handful of
cases which were inconsistent with the rest of the codebase (`void` return
type was already the most common case prior to this commit).
This commit is contained in:
Rémi Verschelde 2021-11-30 15:19:26 +01:00
parent 2d118bd8b8
commit 7da392bcc5
No known key found for this signature in database
GPG key ID: C3336907360768E1
28 changed files with 93 additions and 90 deletions

View file

@ -192,7 +192,7 @@ public:
GDScriptDataType() = default;
GDScriptDataType &operator=(const GDScriptDataType &p_other) {
void operator=(const GDScriptDataType &p_other) {
kind = p_other.kind;
has_type = p_other.has_type;
builtin_type = p_other.builtin_type;
@ -203,7 +203,6 @@ public:
if (p_other.has_container_element_type()) {
set_container_element_type(p_other.get_container_element_type());
}
return *this;
}
GDScriptDataType(const GDScriptDataType &p_other) {

View file

@ -203,7 +203,7 @@ public:
return !(this->operator==(p_other));
}
DataType &operator=(const DataType &p_other) {
void operator=(const DataType &p_other) {
kind = p_other.kind;
type_source = p_other.type_source;
is_constant = p_other.is_constant;
@ -221,7 +221,6 @@ public:
if (p_other.has_container_element_type()) {
set_container_element_type(p_other.get_container_element_type());
}
return *this;
}
DataType() = default;

View file

@ -598,7 +598,7 @@ class BindingsGenerator {
private:
NameCache(const NameCache &);
NameCache &operator=(const NameCache &);
void operator=(const NameCache &);
};
NameCache name_cache;

View file

@ -229,9 +229,6 @@ private:
#endif
}
_GodotSharpDirs(const _GodotSharpDirs &);
_GodotSharpDirs &operator=(const _GodotSharpDirs &);
public:
static _GodotSharpDirs &get_singleton() {
static _GodotSharpDirs singleton;

View file

@ -56,13 +56,12 @@ struct MonoGCHandleData {
void release();
MonoGCHandleData &operator=(const MonoGCHandleData &p_other) {
void operator=(const MonoGCHandleData &p_other) {
#ifdef DEBUG_ENABLED
CRASH_COND(!is_released());
#endif
handle = p_other.handle;
type = p_other.type;
return *this;
}
MonoGCHandleData(const MonoGCHandleData &) = default;

View file

@ -121,12 +121,10 @@ void GDMonoLog::_delete_old_log_files(const String &p_logs_dir) {
ERR_FAIL_COND(da->list_dir_begin() != OK);
String current;
while ((current = da->get_next()).length()) {
if (da->current_is_dir()) {
continue;
}
if (!current.ends_with(".txt")) {
String current = da->get_next();
while (!current.is_empty()) {
if (da->current_is_dir() || !current.ends_with(".txt")) {
current = da->get_next();
continue;
}
@ -135,6 +133,7 @@ void GDMonoLog::_delete_old_log_files(const String &p_logs_dir) {
if (OS::get_singleton()->get_unix_time() - modified_time > MAX_SECS) {
da->remove(current);
}
current = da->get_next();
}
da->list_dir_end();