Skip to content

Commit

Permalink
Consistently use override in tests (#3934)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanTLavavej committed Aug 11, 2023
1 parent 094e533 commit 8674b3d
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Base {

class Derived : public Base {
private:
virtual void purr() {}
void purr() override {}
};

int main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Base {

class Derived : public Base {
public:
virtual string str() const {
string str() const override {
return "Derived";
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class Cat {
};

struct Lion : public Cat {
virtual int meow() const {
int meow() const override {
return 6;
}
};

struct Tiger : public Cat {
virtual int meow() const {
int meow() const override {
return 7;
}
};
Expand All @@ -42,13 +42,13 @@ class Planet {
};

struct Jupiter : public Planet {
virtual int orbit() const {
int orbit() const override {
return 8;
}
};

struct Saturn : public Planet {
virtual int orbit() const {
int orbit() const override {
return 9;
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/std/tests/Dev11_0496153_locale_ctor/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void test_Dev11_496153_locale_ctor_should_not_throw() noexcept {
}

struct comma_separator : numpunct<char> {
virtual char do_decimal_point() const override {
char do_decimal_point() const override {
return ',';
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/std/tests/Dev11_0535636_functional_overhaul/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ struct BaseMeow {
};

struct DerivedMeow : BaseMeow {
virtual int operator()(int x, int y) override {
int operator()(int x, int y) override {
return x * x * x + y * y * y;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int main() {
};

struct Derived final : Base {
virtual void test() override {}
void test() override {}
};

shared_ptr<Base> object;
Expand Down
25 changes: 12 additions & 13 deletions tests/std/tests/P0220R1_polymorphic_memory_resources/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace {

struct malloc_resource final : std::pmr::memory_resource {
private:
virtual void* do_allocate(std::size_t bytes, std::size_t align) override {
void* do_allocate(std::size_t bytes, std::size_t align) override {
if (!bytes) {
return nullptr;
}
Expand All @@ -175,15 +175,15 @@ namespace {
throw std::bad_alloc{};
}

virtual void do_deallocate(void* ptr, std::size_t, std::size_t align) noexcept override {
void do_deallocate(void* ptr, std::size_t, std::size_t align) noexcept override {
if (align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
_aligned_free(ptr);
} else {
std::free(ptr);
}
}

virtual bool do_is_equal(const memory_resource& that) const noexcept override {
bool do_is_equal(const memory_resource& that) const noexcept override {
return typeid(malloc_resource) == typeid(that);
}
};
Expand All @@ -194,7 +194,7 @@ namespace {
void* ptr_{};

private:
virtual void* do_allocate(std::size_t bytes, std::size_t align) override {
void* do_allocate(std::size_t bytes, std::size_t align) override {
if (bytes_ != 0) {
CHECK(bytes == bytes_);
} else {
Expand All @@ -214,7 +214,7 @@ namespace {
}
}

virtual void do_deallocate(void* ptr, std::size_t bytes, std::size_t align) noexcept override {
void do_deallocate(void* ptr, std::size_t bytes, std::size_t align) noexcept override {
if (ptr_) {
CHECK(ptr == ptr_);
if (bytes_ != 0) {
Expand Down Expand Up @@ -245,7 +245,7 @@ namespace {
}
}

virtual bool do_is_equal(const memory_resource& that) const noexcept override {
bool do_is_equal(const memory_resource& that) const noexcept override {
CHECK(ptr_ == &that);
return typeid(checked_resource) == typeid(that);
}
Expand Down Expand Up @@ -273,14 +273,13 @@ namespace {
}
}

virtual void* do_allocate(std::size_t const bytes, std::size_t const align) override {
void* do_allocate(std::size_t const bytes, std::size_t const align) override {
void* const result = upstream_->allocate(bytes, align);
allocations_.push_back({result, bytes, align});
return result;
}

virtual void do_deallocate(
void* const ptr, std::size_t const bytes, std::size_t const align) noexcept override {
void do_deallocate(void* const ptr, std::size_t const bytes, std::size_t const align) noexcept override {
allocation const alloc{ptr, bytes, align};
auto const end = allocations_.end();
auto pos = std::find(allocations_.begin(), end, alloc);
Expand All @@ -289,7 +288,7 @@ namespace {
upstream_->deallocate(ptr, bytes, align);
}

virtual bool do_is_equal(const memory_resource& that) const noexcept override {
bool do_is_equal(const memory_resource& that) const noexcept override {
return this == &that;
}
};
Expand Down Expand Up @@ -496,15 +495,15 @@ namespace {

struct max_align_checker final : std::pmr::memory_resource {
private:
virtual void* do_allocate(std::size_t bytes, std::size_t align) override {
void* do_allocate(std::size_t bytes, std::size_t align) override {
CHECK(align == alignof(std::max_align_t));
return std::malloc(bytes);
}
virtual void do_deallocate(void* ptr, std::size_t, std::size_t align) override {
void do_deallocate(void* ptr, std::size_t, std::size_t align) override {
CHECK(align == alignof(std::max_align_t));
std::free(ptr);
}
virtual bool do_is_equal(const memory_resource& that) const noexcept override {
bool do_is_equal(const memory_resource& that) const noexcept override {
return typeid(max_align_checker) == typeid(that);
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/std/tests/P0476R2_bit_cast/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct middle_class_2 {
};

struct derived_class : middle_class_1, middle_class_2 {
virtual void a_member_function_2() override {}
void a_member_function_2() override {}
};

struct test_struct_1 {
Expand Down
4 changes: 2 additions & 2 deletions tests/std/tests/P0645R10_text_formatting_formatting/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,11 @@ void test_bool_specs() {
assert(format(locale{"en-US"}, STR("{:L}"), false) == STR("false"));

struct my_bool : numpunct<charT> {
virtual basic_string<charT> do_truename() const {
basic_string<charT> do_truename() const override {
return STR("yes");
}

virtual basic_string<charT> do_falsename() const {
basic_string<charT> do_falsename() const override {
return STR("no");
}
};
Expand Down
12 changes: 6 additions & 6 deletions tests/tr1/tests/future1/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ class future_tester_base { // base class for testing future types with set and g

template <template <class T> class Future>
class future_value_tester : public future_tester_base<Future, int> { // class for testing Future<T>
virtual void do_set_value() override { // set the value
void do_set_value() override { // set the value
this->pr.set_value(3);
}
virtual void do_check_value() override { // check the value
void do_check_value() override { // check the value
CHECK_INT(this->fut.get(), 3);
}
};
Expand All @@ -120,22 +120,22 @@ class future_reference_tester : public future_tester_base<Future, int&> { // cla
}

private:
virtual void do_set_value() override { // set the value
void do_set_value() override { // set the value
value = 3;
this->pr.set_value(value);
}
virtual void do_check_value() override { // check the value
void do_check_value() override { // check the value
CHECK_INT(this->fut.get(), 3);
}
int value;
};

template <template <class T> class Future>
class future_void_tester : public future_tester_base<Future, void> { // class for testing Future<void>
virtual void do_set_value() override { // set the value
void do_set_value() override { // set the value
this->pr.set_value();
}
virtual void do_check_value() override { // get the value
void do_check_value() override { // get the value
this->fut.get(); // do not remove
}
};
Expand Down
16 changes: 8 additions & 8 deletions tests/tr1/tests/locale1/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,23 @@ void test_ctype() { // test ctype<char>

struct Myxnpunct : public STD numpunct<char> { // specify numeric punctuation
protected:
virtual char do_decimal_point() const { // return decimal point
char do_decimal_point() const override { // return decimal point
return '_';
}

virtual char do_thousands_sep() const { // return thousands separator
char do_thousands_sep() const override { // return thousands separator
return ';';
}

virtual STD string do_grouping() const { // return grouping rule
STD string do_grouping() const override { // return grouping rule
return "\2";
}

virtual STD string do_truename() const { // return name for true
STD string do_truename() const override { // return name for true
return "yes";
}

virtual STD string do_falsename() const { // return name for false
STD string do_falsename() const override { // return name for false
return "no";
}
};
Expand All @@ -232,7 +232,7 @@ struct Myxctype2 : public STD ctype<char> { // get protected members
Myxctype2() { // default construct
}

virtual char do_widen(char ch) const { // widen a character
char do_widen(char ch) const override { // widen a character
if (ch == '-') {
return '@';
} else if (ch == '0') {
Expand All @@ -244,8 +244,8 @@ struct Myxctype2 : public STD ctype<char> { // get protected members
}
}

virtual const char* do_widen(const char* first, const char* last,
char* dest) const { // widen a character sequence
const char* do_widen(const char* first, const char* last,
char* dest) const override { // widen a character sequence
for (; first != last; ++first, ++dest) {
*dest = do_widen(*first);
}
Expand Down
16 changes: 8 additions & 8 deletions tests/tr1/tests/locale2/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,23 @@ void test_ctype() { // test ctype<wchar_t>

struct Myxnpunct : public STD numpunct<wchar_t> { // specify numeric punctuation
protected:
virtual wchar_t do_decimal_point() const { // return decimal point
wchar_t do_decimal_point() const override { // return decimal point
return L'_';
}

virtual wchar_t do_thousands_sep() const { // return thousands separator
wchar_t do_thousands_sep() const override { // return thousands separator
return L';';
}

virtual STD string do_grouping() const { // return grouping rule
STD string do_grouping() const override { // return grouping rule
return "\2";
}

virtual STD wstring do_truename() const { // return name for true
STD wstring do_truename() const override { // return name for true
return L"yes";
}

virtual STD wstring do_falsename() const { // return name for false
STD wstring do_falsename() const override { // return name for false
return L"no";
}
};
Expand All @@ -165,7 +165,7 @@ struct Myxctype2 : public STD ctype<wchar_t> { // get protected members
Myxctype2() { // default construct
}

virtual wchar_t do_widen(char ch) const { // widen a character
wchar_t do_widen(char ch) const override { // widen a character
if (ch == '-') {
return L'@';
} else if (ch == '0') {
Expand All @@ -177,8 +177,8 @@ struct Myxctype2 : public STD ctype<wchar_t> { // get protected members
}
}

virtual const char* do_widen(const char* first, const char* last,
wchar_t* dest) const { // widen a character sequence
const char* do_widen(const char* first, const char* last,
wchar_t* dest) const override { // widen a character sequence
for (; first != last; ++first, ++dest) {
*dest = do_widen(*first);
}
Expand Down
Loading

0 comments on commit 8674b3d

Please sign in to comment.