Skip to content

Commit

Permalink
Always initialize fields in MatcherBase constructors
Browse files Browse the repository at this point in the history
This fixes -Wuninitialized warnings with GCC.

Fixes #3514.
  • Loading branch information
glandium committed Apr 20, 2022
1 parent 8ccdb9d commit d5ad28d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions googletest/include/gtest/gtest-matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,18 @@ class MatcherBase : private MatcherDescriberInterface {
}

protected:
MatcherBase() : vtable_(nullptr) {}
MatcherBase() : vtable_(nullptr), buffer_() {}

// Constructs a matcher from its implementation.
template <typename U>
explicit MatcherBase(const MatcherInterface<U>* impl) {
explicit MatcherBase(const MatcherInterface<U>* impl)
: vtable_(nullptr), buffer_() {
Init(impl);
}

template <typename M, typename = typename std::remove_reference<
M>::type::is_gtest_matcher>
MatcherBase(M&& m) { // NOLINT
MatcherBase(M&& m) : vtable_(nullptr), buffer_() { // NOLINT
Init(std::forward<M>(m));
}

Expand Down

1 comment on commit d5ad28d

@supernun
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be better to have done in-class initialization directly?

Buffer buffer_{};

Please sign in to comment.