diff options
| author | Martin Hořeňovský | 2020-02-01 20:55:42 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-02-16 16:02:31 +0100 |
| commit | f8794634c286810ee97544e1e4ea0cbd1555d66d (patch) | |
| tree | 54f9ff713fbc957c5e996b40ad43bf5fb47c2e0a /src/catch2 | |
| parent | d6b2a3793b6693ac8f51283f6e22cfed9f1eb230 (diff) | |
| download | catch3-f8794634c286810ee97544e1e4ea0cbd1555d66d.tar.gz | |
Fix significant bug with storing composed matchers
Given that in the 2 or so years that matchers are thing nobody complained,
it seems that people do not actually write this sort of code, and the
possibility will be removed in v3. However, to avoid correctness bugs,
we will have to support this weird code in v2.
Diffstat (limited to 'src/catch2')
| -rw-r--r-- | src/catch2/catch_matchers.h | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/catch2/catch_matchers.h b/src/catch2/catch_matchers.h index 78d9e84e..08b69584 100644 --- a/src/catch2/catch_matchers.h +++ b/src/catch2/catch_matchers.h @@ -91,9 +91,10 @@ namespace Matchers { return description; } - MatchAllOf<ArgT>& operator && ( MatcherBase<ArgT> const& other ) { - m_matchers.push_back( &other ); - return *this; + MatchAllOf<ArgT> operator && ( MatcherBase<ArgT> const& other ) { + auto copy(*this); + copy.m_matchers.push_back( &other ); + return copy; } std::vector<MatcherBase<ArgT> const*> m_matchers; @@ -124,9 +125,10 @@ namespace Matchers { return description; } - MatchAnyOf<ArgT>& operator || ( MatcherBase<ArgT> const& other ) { - m_matchers.push_back( &other ); - return *this; + MatchAnyOf<ArgT> operator || ( MatcherBase<ArgT> const& other ) { + auto copy(*this); + copy.m_matchers.push_back( &other ); + return copy; } std::vector<MatcherBase<ArgT> const*> m_matchers; |