mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 11:43:29 +01:00
Document that matcher combinators (&&, ||, !) do not take ownership
Closes #1781
This commit is contained in:
parent
50cc14c94c
commit
c5c688820c
@ -35,6 +35,22 @@ REQUIRE_THAT( str,
|
|||||||
(StartsWith( "Big data" ) && !Contains( "web scale" ) ) );
|
(StartsWith( "Big data" ) && !Contains( "web scale" ) ) );
|
||||||
```
|
```
|
||||||
|
|
||||||
|
_The combining operators do not take ownership of the matcher objects.
|
||||||
|
This means that if you store the combined object, you have to ensure that
|
||||||
|
the matcher objects outlive its last use. What this means is that code
|
||||||
|
like this leads to a use-after-free and (hopefully) a crash:_
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
TEST_CASE("Bugs, bugs, bugs", "[Bug]"){
|
||||||
|
std::string str = "Bugs as a service";
|
||||||
|
|
||||||
|
auto match_expression = Catch::EndsWith( "as a service" ) ||
|
||||||
|
(Catch::StartsWith( "Big data" ) && !Catch::Contains( "web scale" ) );
|
||||||
|
REQUIRE_THAT(str, match_expression);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Built in matchers
|
## Built in matchers
|
||||||
Catch2 provides some matchers by default. They can be found in the
|
Catch2 provides some matchers by default. They can be found in the
|
||||||
`Catch::Matchers::foo` namespace and are imported into the `Catch`
|
`Catch::Matchers::foo` namespace and are imported into the `Catch`
|
||||||
|
Loading…
Reference in New Issue
Block a user