llvm.org GIT mirror llvm / 8a4b825
Revert "raw_ostream: add operator<< overload for std::error_code" This reverts commit r368849, because it breaks some bots (e.g. llvm-clang-x86_64-win-fast). It turns out this is not as NFC as we had hoped, because operator== will consider two std::error_codes to be distinct even though they both hold "success" values if they have different categories. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368854 91177308-0d34-0410-b5e6-96231b3b80d8 Pavel Labath a month ago
10 changed file(s) with 78 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
221221 }
222222
223223 raw_ostream &operator<<(double N);
224
225 raw_ostream &operator<<(std::error_code EC);
226224
227225 /// Output \p N in hexadecimal, without any prefix or padding.
228226 raw_ostream &write_hex(unsigned long long N);
138138 return *this;
139139 }
140140
141 raw_ostream &raw_ostream::operator<<(std::error_code EC) {
142 return *this << EC.message() << " (" << EC.category().name() << ':'
143 << EC.value() << ')';
144 }
145
146141 raw_ostream &raw_ostream::write_hex(unsigned long long N) {
147142 llvm::write_hex(*this, N, HexPrintStyle::Lower);
148143 return *this;
1616 using namespace llvm;
1717 namespace fs = llvm::sys::fs;
1818
19 #define ASSERT_NO_ERROR(x) ASSERT_EQ(x, std::error_code())
19 #define ASSERT_NO_ERROR(x) \
20 if (std::error_code ASSERT_NO_ERROR_ec = x) { \
21 SmallString<128> MessageStorage; \
22 raw_svector_ostream Message(MessageStorage); \
23 Message << #x ": did not return errc::success.\n" \
24 << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
25 << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
26 GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
27 } else { \
28 }
2029
2130 class MagicTest : public testing::Test {
2231 protected:
932932
933933 class TestErrorCategory : public std::error_category {
934934 public:
935 const char *name() const noexcept override { return "test_error"; }
935 const char *name() const noexcept override { return "error"; }
936936 std::string message(int Condition) const override {
937937 switch (static_cast(Condition)) {
938938 case test_error_code::unspecified:
974974 0);
975975 }
976976
977 TEST(Error, error_codeErrorMessageTest) {
978 EXPECT_NONFATAL_FAILURE(
979 EXPECT_EQ(make_error_code(test_error_code::unspecified),
980 make_error_code(test_error_code::error_2)),
981 "Which is: An unknown error has occurred. (test_error:1)");
982 }
983
984977 } // namespace
1717 using namespace llvm;
1818 using namespace llvm::sys;
1919
20 #define ASSERT_NO_ERROR(x) ASSERT_EQ(x, std::error_code())
20 #define ASSERT_NO_ERROR(x) \
21 if (std::error_code ASSERT_NO_ERROR_ec = x) { \
22 SmallString<128> MessageStorage; \
23 raw_svector_ostream Message(MessageStorage); \
24 Message << #x ": did not return errc::success.\n" \
25 << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
26 << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
27 GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
28 } else { \
29 }
2130
2231 namespace {
2332 TEST(FileOutputBuffer, Test) {
1515
1616 #include "gtest/gtest.h"
1717
18 #define ASSERT_NO_ERROR(x) ASSERT_EQ(x, std::error_code())
18 #define ASSERT_NO_ERROR(x) \
19 if (std::error_code ASSERT_NO_ERROR_ec = x) { \
20 SmallString<128> MessageStorage; \
21 raw_svector_ostream Message(MessageStorage); \
22 Message << #x ": did not return errc::success.\n" \
23 << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
24 << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
25 GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
26 } else { \
27 }
1928
2029 using namespace llvm;
2130
3737 using namespace llvm;
3838 using namespace llvm::sys;
3939
40 #define ASSERT_NO_ERROR(x) ASSERT_EQ(x, std::error_code())
41 #define ASSERT_ERROR(x) ASSERT_NE(x, std::error_code())
40 #define ASSERT_NO_ERROR(x) \
41 if (std::error_code ASSERT_NO_ERROR_ec = x) { \
42 SmallString<128> MessageStorage; \
43 raw_svector_ostream Message(MessageStorage); \
44 Message << #x ": did not return errc::success.\n" \
45 << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
46 << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
47 GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
48 } else { \
49 }
50
51 #define ASSERT_ERROR(x) \
52 if (!x) { \
53 SmallString<128> MessageStorage; \
54 raw_svector_ostream Message(MessageStorage); \
55 Message << #x ": did not return a failure error code.\n"; \
56 GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
57 }
4258
4359 namespace {
4460
12481264 int FileDescriptor2;
12491265 SmallString<64> ResultPath;
12501266 ASSERT_NO_ERROR(fs::openFileForRead(Twine(TempPath), FileDescriptor2,
1251 fs::OF_None, &ResultPath));
1267 fs::OF_None, &ResultPath))
12521268
12531269 // If we succeeded, check that the paths are the same (modulo case):
12541270 if (!ResultPath.empty()) {
3434 #error sleep_for is not implemented on your platform.
3535 #endif
3636
37 #define ASSERT_NO_ERROR(x) ASSERT_EQ(x, std::error_code())
38
37 #define ASSERT_NO_ERROR(x) \
38 if (std::error_code ASSERT_NO_ERROR_ec = x) { \
39 SmallString<128> MessageStorage; \
40 raw_svector_ostream Message(MessageStorage); \
41 Message << #x ": did not return errc::success.\n" \
42 << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
43 << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
44 GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
45 } else { \
46 }
3947 // From TestMain.cpp.
4048 extern const char *TestMainArgv0;
4149
1616 using namespace llvm;
1717 using namespace llvm::sys;
1818
19 #define ASSERT_NO_ERROR(x) ASSERT_EQ(x, std::error_code())
19 #define ASSERT_NO_ERROR(x) \
20 do { \
21 if (std::error_code ASSERT_NO_ERROR_ec = x) { \
22 errs() << #x ": did not return errc::success.\n" \
23 << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
24 << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
25 } \
26 } while (false)
2027
2128 namespace {
2229 std::error_code CreateFileWithContent(const SmallString<128> &FilePath,
1414
1515 using namespace llvm;
1616
17 #define ASSERT_NO_ERROR(x) ASSERT_EQ(x, std::error_code())
17 #define ASSERT_NO_ERROR(x) \
18 if (std::error_code ASSERT_NO_ERROR_ec = x) { \
19 SmallString<128> MessageStorage; \
20 raw_svector_ostream Message(MessageStorage); \
21 Message << #x ": did not return errc::success.\n" \
22 << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
23 << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
24 GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
25 } else { \
26 }
1827
1928 namespace {
2029