Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enums with ostream<< overloads are printed as their underlying type (as integers) #678

Closed
nlguillemot opened this issue Aug 4, 2022 · 0 comments · Fixed by #710
Closed

Comments

@nlguillemot
Copy link

Description

I had some enums where I defined an ostream<< operator, and I want to use it to print my enums rather than printing their underlying value like doctest seems to do by default.

Steps to reproduce

enum class Foo {};

std::ostream& operator<<(std::ostream& os, Foo) {
  return os << "Foo";
}

int main() {
    assert(doctest::toString(Foo()) == "Foo"); // Fails, toString returns "0"
}

(disclaimer: I have not tested the example code above.)

Extra information

I found a workaround but it only works for GCC (see: #121 (comment))

I suggest to tweak doctest's enum printing code so that it only prints enums by their underlying type if they do not meet the requirements of has_insertion_operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants