[PATCH] D153930: [unittest] teach gTest to print entries of DenseMap as pairs

Martin Böhme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 27 21:07:51 PDT 2023


mboehme accepted this revision.
mboehme added a comment.
This revision is now accepted and ready to land.

This is a great quality-of-life improvement!

I agree that the practical risk of referring to `DenseMapPair` is low. If it ever does change so it no longer inherits from `std::pair` then, in the worst case, we can remove the `PrintTo` overload introduced here and be in a no worse position than before. (Preferably, though, we would change the implementation so that it continues to print the same thing.)



================
Comment at: third-party/unittest/googletest/include/gtest/internal/custom/gtest-printers.h:74
+inline void PrintTo(const DenseMapPair<K, V> &Pair, std::ostream *OS) {
+  *OS << ::testing::PrintToString(static_cast<const std::pair<K, V> &>(Pair));
+}
----------------
Is there a reason we can't simply do this?

```
::testing::PrintTo(static_cast<const std::pair<K, V> &>(Pair), OS);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153930



More information about the llvm-commits mailing list