diff --git a/core/include/cubos/core/reflection/traits/fields.hpp b/core/include/cubos/core/reflection/traits/fields.hpp index a5e7f1a1f..c6555462b 100644 --- a/core/include/cubos/core/reflection/traits/fields.hpp +++ b/core/include/cubos/core/reflection/traits/fields.hpp @@ -143,7 +143,7 @@ namespace cubos::core::reflection /// @brief Move constructs. /// @param other Other trait. - FieldsTrait(FieldsTrait&& other); + FieldsTrait(FieldsTrait&& other) noexcept ; /// @brief Adds a field to the type. The getter will be deleted using `delete` and thus /// must be allocated using `new`. @@ -176,7 +176,7 @@ namespace cubos::core::reflection /// @brief Gets an iterator which represents the end of the field list of a type. /// @return Iterator. - Iterator end() const; + static Iterator end(); private: Field* mFirstField; diff --git a/core/samples/reflection/traits/fields/main.cpp b/core/samples/reflection/traits/fields/main.cpp index cbc86a80c..0c603a1cb 100644 --- a/core/samples/reflection/traits/fields/main.cpp +++ b/core/samples/reflection/traits/fields/main.cpp @@ -40,7 +40,7 @@ int main() /// [Accessing the trait] /// [Iterating over fields] - for (auto& field : fields) + for (const auto& field : fields) { CUBOS_INFO("Field '{}' of type '{}'", field.name(), field.type().name()); } diff --git a/core/src/cubos/core/reflection/traits/fields.cpp b/core/src/cubos/core/reflection/traits/fields.cpp index 2d647f15a..b9630f411 100644 --- a/core/src/cubos/core/reflection/traits/fields.cpp +++ b/core/src/cubos/core/reflection/traits/fields.cpp @@ -78,7 +78,7 @@ FieldsTrait::FieldsTrait() } FieldsTrait::FieldsTrait(FieldsTrait&& other) - : mFirstField(other.mFirstField) + noexcept : mFirstField(other.mFirstField) , mLastField(other.mLastField) { other.mFirstField = nullptr; @@ -87,9 +87,9 @@ FieldsTrait::FieldsTrait(FieldsTrait&& other) FieldsTrait::~FieldsTrait() { - while (mFirstField) + while (mFirstField != nullptr) { - auto next = mFirstField->mNext; + auto *next = mFirstField->mNext; delete mFirstField; mFirstField = next; } @@ -97,13 +97,13 @@ FieldsTrait::~FieldsTrait() FieldsTrait&& FieldsTrait::withField(const Type& type, std::string name, AddressOf* addressOf) && { - for (auto field = mFirstField; field; field = field->mNext) + for (auto *field = mFirstField; field != nullptr; field = field->mNext) { CUBOS_ASSERT(field->mName != name, "Field '{}' already exists", name); } - auto field = new Field(type, std::move(name), addressOf); - if (mFirstField) + auto *field = new Field(type, std::move(name), addressOf); + if (mFirstField != nullptr) { mLastField->mNext = field; mLastField = field; @@ -119,7 +119,7 @@ FieldsTrait&& FieldsTrait::withField(const Type& type, std::string name, Address const FieldsTrait::Field* FieldsTrait::field(const std::string& name) const { - for (auto field = mFirstField; field; field = field->mNext) + for (auto *field = mFirstField; field != nullptr; field = field->mNext) { if (field->mName == name) { @@ -136,7 +136,7 @@ FieldsTrait::Iterator FieldsTrait::begin() const return Iterator{mFirstField}; } -FieldsTrait::Iterator FieldsTrait::end() const +FieldsTrait::Iterator FieldsTrait::end() { return Iterator{nullptr}; } diff --git a/core/tests/reflection/traits/fields.cpp b/core/tests/reflection/traits/fields.cpp index 41c13b3dc..1d760b594 100644 --- a/core/tests/reflection/traits/fields.cpp +++ b/core/tests/reflection/traits/fields.cpp @@ -34,7 +34,7 @@ TEST_CASE("reflection::FieldsTrait") { auto fields = FieldsTrait().withField("foo", &ObjectType::foo); - auto field = fields.field("foo"); + const auto *field = fields.field("foo"); REQUIRE(field != nullptr); CHECK(field == &*fields.begin()); CHECK(++fields.begin() == fields.end()); @@ -49,11 +49,11 @@ TEST_CASE("reflection::FieldsTrait") { auto fields = FieldsTrait().withField("foo", &ObjectType::foo).withField("bar", &ObjectType::bar); - auto fooField = fields.field("foo"); + const auto *fooField = fields.field("foo"); REQUIRE(fooField != nullptr); CHECK(fooField == &*fields.begin()); - auto barField = fields.field("bar"); + const auto *barField = fields.field("bar"); REQUIRE(barField != nullptr); CHECK(barField == &*(++fields.begin())); CHECK(++(++fields.begin()) == fields.end());