google / google/googletest

[Bug]: user-defined `PrintTo()` not respected by `Message::operator<<` template

Open
#4,204 4 comments 0 reactions 1 assignee Claimed by @asoffer View on GitHub
Dominant language
C++
Stars
39.5k
Forks
10.9k
Avg merge
6d 13h
Merged PRs (30d)
1

Description

### Describe the issue

Based on the documentation: https://github.com/google/googletest/blob/v1.13.x/docs/advanced.md#teaching-googletest-how-to-print-your-values it seems that defining a `void PrintTo(const T&, std::ostream&)` function should teach googletest how to print custom values of type `T`

However, this does not work for custom error messages, e.g.

```
// assume void PrintTo(const T&, std::ostream&) is defined
T foo;
EXPECT_EQ(3, 2) << foo;
```

Does not compile.

### Steps to reproduce the problem

https://godbolt.org/z/cvx4b65qc

### What version of GoogleTest are you using?

release v1.13.0

### What operating system and version are you using?

Debian GNU/Linux 11 (bullseye)

### What compiler and version are you using?

Clang 16.0.0

But the problem does not seem compiler specific.

### What build system are you using?

not using a build system.

### Additional context

I'm not sure if this is supposed to work. The docs made me think it should work, but perhaps it's not supposed to work, in which case maybe the docs should be upgraded.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.