[PATCH] D65643: raw_ostream: add operator<< overload for std::error_code

Pavel Labath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 14 07:34:41 PDT 2019


labath added a comment.

Unfortunately, I've hit a snag with this implementation. It turns out changing `bool(EC)` to `EC != std::error_code()` is not NFC because one can have two "success" values that still compare as unequal (e.g. `std::error_code(0, generic_category())` and `std::error_code(0, system_category())`. This is a problem because `std::error_code()` is `std::error_code(0, system_category())` and there some (though few) places in llvm that do `return std::error_code(errno, generic_category())`, and at least some of those places are not bugs (though I think some are).

So I don't think we can go for the `EXPECT_EQ(EC, std::error_code())` option. This unfortunately brings us back to square one. I think the only way to reasonably implement this is to go the matcher route, as that is the only way (that I know of) we can call `operator bool` to properly determine success-ness of the value, while still being able to print the exact failure message. (Though we can keep the `operator<<` overload, so that matching direct matching against a known error code still works.)

What do you think ?


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65643/new/

https://reviews.llvm.org/D65643





More information about the llvm-commits mailing list