googletest icon indicating copy to clipboard operation
googletest copied to clipboard

Example for "Defining a Custom Matcher Class" does not compile

Open tom-anders opened this issue 3 years ago • 2 comments

Describe the bug

Trying out the example from https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#defining-a-custom-matcher-class-custommatcherclass results in error: could not convert ‘BarPlusBazEqMatcher(expected_sum)’ from ‘BarPlusBazEqMatcher’ to ‘testing::Matcher<const Foo&>’

Steps to reproduce the bug

Copy the example (BarPlusBazEqMatcher), add struct Foo { int bar() const; int baz() const; }; to the top of the file), try to compile it.

Does the bug persist in the most recent commit?

Yes

What operating system and version are you using?

Ubuntu 20.04

What compiler and version are you using?

gcc 9.4.0

What build system are you using?

Plain command line

Additional context

I took a look at the source and found that the solution seems to be to inherit from testing::MatcherInterface<T> instead?

tom-anders avatar Jul 11 '22 07:07 tom-anders

same issue found when following the guide. OS version: Ubuntu 18.04 G++ version: 7.5.0

yangwang201911 avatar Oct 27 '22 09:10 yangwang201911

Can confirm, the example from the guide does not compile.

roel-gerrits avatar Dec 21 '22 10:12 roel-gerrits