[llvm-commits] [llvm] r81093 - in /llvm/trunk: unittests/Support/ConstantRangeTest.cpp utils/unittest/googletest/README.LLVM utils/unittest/googletest/include/gtest/internal/gtest-internal.h
Jeffrey Yasskin
jyasskin at google.com
Sat Sep 5 11:16:17 PDT 2009
Author: jyasskin
Date: Sat Sep 5 13:16:17 2009
New Revision: 81093
URL: http://llvm.org/viewvc/llvm-project?rev=81093&view=rev
Log:
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.
Modified:
llvm/trunk/unittests/Support/ConstantRangeTest.cpp
llvm/trunk/utils/unittest/googletest/README.LLVM
llvm/trunk/utils/unittest/googletest/include/gtest/internal/gtest-internal.h
Modified: llvm/trunk/unittests/Support/ConstantRangeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ConstantRangeTest.cpp?rev=81093&r1=81092&r2=81093&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/ConstantRangeTest.cpp (original)
+++ llvm/trunk/unittests/Support/ConstantRangeTest.cpp Sat Sep 5 13:16:17 2009
@@ -16,13 +16,6 @@
namespace {
-// Support APInt output to an std::ostream.
-inline std::ostream &operator<<(std::ostream &OS, const APInt &Value) {
- raw_os_ostream RawOS(OS);
- RawOS << Value;
- return OS;
-}
-
class ConstantRangeTest : public ::testing::Test {
protected:
static ConstantRange Full;
Modified: llvm/trunk/utils/unittest/googletest/README.LLVM
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/unittest/googletest/README.LLVM?rev=81093&r1=81092&r2=81093&view=diff
==============================================================================
--- llvm/trunk/utils/unittest/googletest/README.LLVM (original)
+++ llvm/trunk/utils/unittest/googletest/README.LLVM Sat Sep 5 13:16:17 2009
@@ -24,3 +24,8 @@
$ 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.
Modified: llvm/trunk/utils/unittest/googletest/include/gtest/internal/gtest-internal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/unittest/googletest/include/gtest/internal/gtest-internal.h?rev=81093&r1=81092&r2=81093&view=diff
==============================================================================
--- llvm/trunk/utils/unittest/googletest/include/gtest/internal/gtest-internal.h (original)
+++ llvm/trunk/utils/unittest/googletest/include/gtest/internal/gtest-internal.h Sat Sep 5 13:16:17 2009
@@ -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 {
More information about the llvm-commits
mailing list