diff options
author | Jeffrey Yasskin <jyasskin@google.com> | 2009-09-05 18:16:17 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@google.com> | 2009-09-05 18:16:17 +0000 |
commit | b797fdc365dc15558da3d75dbfb7ea2f8c219816 (patch) | |
tree | eb2ae6534595b85fb2ad187b6134216040c534dd /llvm/utils | |
parent | b5850f9c80587893cc790a85bd08ad58179b8d49 (diff) | |
download | bcm5719-llvm-b797fdc365dc15558da3d75dbfb7ea2f8c219816.tar.gz bcm5719-llvm-b797fdc365dc15558da3d75dbfb7ea2f8c219816.zip |
Teach googletest to use raw_ostream instead of just std::ostream.
This can break when there are implicit conversions from types raw_ostream
understands but std::ostream doesn't, but it increases the number of cases that
Just Work.
llvm-svn: 81093
Diffstat (limited to 'llvm/utils')
-rw-r--r-- | llvm/utils/unittest/googletest/README.LLVM | 5 | ||||
-rw-r--r-- | llvm/utils/unittest/googletest/include/gtest/internal/gtest-internal.h | 22 |
2 files changed, 26 insertions, 1 deletions
diff --git a/llvm/utils/unittest/googletest/README.LLVM b/llvm/utils/unittest/googletest/README.LLVM index 2c673cc6ab7..e907a5e6ea2 100644 --- a/llvm/utils/unittest/googletest/README.LLVM +++ b/llvm/utils/unittest/googletest/README.LLVM @@ -24,3 +24,8 @@ $ perl -pi -e 's|^#include "src/|#include "gtest/internal/|' *.cc $ rm -f gtest-all.cc gtest_main.cc $ mv COPYING LICENSE.TXT + + +Modified as follows: +* To GTestStreamToHelper in include/gtest/internal/gtest-internal.h, + added the ability to stream with raw_os_ostream. diff --git a/llvm/utils/unittest/googletest/include/gtest/internal/gtest-internal.h b/llvm/utils/unittest/googletest/include/gtest/internal/gtest-internal.h index 37faaaebea4..242ffea12f9 100644 --- a/llvm/utils/unittest/googletest/include/gtest/internal/gtest-internal.h +++ b/llvm/utils/unittest/googletest/include/gtest/internal/gtest-internal.h @@ -56,6 +56,8 @@ #include <gtest/internal/gtest-filepath.h> #include <gtest/internal/gtest-type-util.h> +#include "llvm/Support/raw_os_ostream.h" + // Due to C++ preprocessor weirdness, we need double indirection to // concatenate two tokens when one of them is __LINE__. Writing // @@ -92,9 +94,27 @@ // ::operator<<;" in the definition of Message's operator<<. That fix // doesn't require a helper function, but unfortunately doesn't // compile with MSVC. + +// LLVM INTERNAL CHANGE: To allow operator<< to work with both +// std::ostreams and LLVM's raw_ostreams, we define a special +// std::ostream with an implicit conversion to raw_ostream& and stream +// to that. This causes the compiler to prefer std::ostream overloads +// but still find raw_ostream& overloads. +namespace llvm { +class convertible_fwd_ostream : public std::ostream { + std::ostream& os_; + raw_os_ostream ros_; + +public: + convertible_fwd_ostream(std::ostream& os) + : std::ostream(os.rdbuf()), os_(os), ros_(*this) {} + operator raw_ostream&() { return ros_; } +}; +} template <typename T> inline void GTestStreamToHelper(std::ostream* os, const T& val) { - *os << val; + llvm::convertible_fwd_ostream cos(*os); + cos << val; } namespace testing { |