File: | unittests/Support/ErrorOrTest.cpp |
Location: | line 36, column 3 |
Description: | Function call argument is an uninitialized value |
1 | //===- unittests/ErrorOrTest.cpp - ErrorOr.h tests ------------------------===// | ||
2 | // | ||
3 | // The LLVM Compiler Infrastructure | ||
4 | // | ||
5 | // This file is distributed under the University of Illinois Open Source | ||
6 | // License. See LICENSE.TXT for details. | ||
7 | // | ||
8 | //===----------------------------------------------------------------------===// | ||
9 | |||
10 | #include "llvm/Support/ErrorOr.h" | ||
11 | #include "llvm/Support/Errc.h" | ||
12 | #include "gtest/gtest.h" | ||
13 | #include <memory> | ||
14 | |||
15 | using namespace llvm; | ||
16 | |||
17 | namespace { | ||
18 | |||
19 | ErrorOr<int> t1() {return 1;} | ||
20 | ErrorOr<int> t2() { return errc::invalid_argument; } | ||
21 | |||
22 | TEST(ErrorOr, SimpleValue)class ErrorOr_SimpleValue_Test : public ::testing::Test { public : ErrorOr_SimpleValue_Test() {} private: virtual void TestBody (); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ErrorOr_SimpleValue_Test(ErrorOr_SimpleValue_Test const &); void operator=(ErrorOr_SimpleValue_Test const & );};::testing::TestInfo* const ErrorOr_SimpleValue_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ErrorOr", "SimpleValue" , __null, __null, (::testing::internal::GetTestTypeId()), ::testing ::Test::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing::internal::TestFactoryImpl< ErrorOr_SimpleValue_Test >);void ErrorOr_SimpleValue_Test::TestBody() { | ||
23 | ErrorOr<int> a = t1(); | ||
24 | // FIXME: This is probably a bug in gtest. EXPECT_TRUE should expand to | ||
25 | // include the !! to make it friendly to explicit bool operators. | ||
26 | EXPECT_TRUE(!!a)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!!a)) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn255820/unittests/Support/ErrorOrTest.cpp" , 26, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "!!a", "false", "true").c_str()) = ::testing::Message(); | ||
27 | EXPECT_EQ(1, *a)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(1)) == 1)>::Compare("1", "*a" , 1, *a))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn255820/unittests/Support/ErrorOrTest.cpp" , 27, gtest_ar.failure_message()) = ::testing::Message(); | ||
28 | |||
29 | ErrorOr<int> b = a; | ||
30 | EXPECT_EQ(1, *b)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(1)) == 1)>::Compare("1", "*b" , 1, *b))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn255820/unittests/Support/ErrorOrTest.cpp" , 30, gtest_ar.failure_message()) = ::testing::Message(); | ||
31 | |||
32 | a = t2(); | ||
33 | EXPECT_FALSE(a)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(a))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn255820/unittests/Support/ErrorOrTest.cpp" , 33, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "a", "true", "false").c_str()) = ::testing::Message(); | ||
34 | EXPECT_EQ(a.getError(), errc::invalid_argument)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(a.getError())) == 1)>::Compare ("a.getError()", "errc::invalid_argument", a.getError(), errc ::invalid_argument))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn255820/unittests/Support/ErrorOrTest.cpp" , 34, gtest_ar.failure_message()) = ::testing::Message(); | ||
35 | #ifdef EXPECT_DEBUG_DEATH | ||
36 | EXPECT_DEBUG_DEATH(*a, "Cannot get value when an error exists")switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { const ::testing::internal::RE& gtest_regex = ("Cannot get value when an error exists" ); ::testing::internal::DeathTest* gtest_dt; if (!::testing:: internal::DeathTest::Create("*a", >est_regex, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn255820/unittests/Support/ErrorOrTest.cpp" , 36, >est_dt)) { goto gtest_label_36; } if (gtest_dt != __null) { ::testing::internal::scoped_ptr< ::testing::internal ::DeathTest> gtest_dt_ptr(gtest_dt); switch (gtest_dt-> AssumeRole()) { case ::testing::internal::DeathTest::OVERSEE_TEST : if (!gtest_dt->Passed(::testing::internal::ExitedUnsuccessfully (gtest_dt->Wait()))) { goto gtest_label_36; } break; case :: testing::internal::DeathTest::EXECUTE_TEST: { ::testing::internal ::DeathTest::ReturnSentinel gtest_sentinel(gtest_dt); if (::testing ::internal::AlwaysTrue()) { *a; }; gtest_dt->Abort(::testing ::internal::DeathTest::TEST_DID_NOT_DIE); break; } } } } else gtest_label_36: ::testing::internal::AssertHelper(::testing:: TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn255820/unittests/Support/ErrorOrTest.cpp" , 36, ::testing::internal::DeathTest::LastMessage()) = ::testing ::Message(); | ||
Within the expansion of the macro 'EXPECT_DEBUG_DEATH':
| |||
37 | #endif | ||
38 | } | ||
39 | |||
40 | ErrorOr<std::unique_ptr<int> > t3() { | ||
41 | return std::unique_ptr<int>(new int(3)); | ||
42 | } | ||
43 | |||
44 | TEST(ErrorOr, Types)class ErrorOr_Types_Test : public ::testing::Test { public: ErrorOr_Types_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); ErrorOr_Types_Test (ErrorOr_Types_Test const &); void operator=(ErrorOr_Types_Test const &);};::testing::TestInfo* const ErrorOr_Types_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ErrorOr", "Types", __null, __null, (::testing::internal::GetTestTypeId ()), ::testing::Test::SetUpTestCase, ::testing::Test::TearDownTestCase , new ::testing::internal::TestFactoryImpl< ErrorOr_Types_Test >);void ErrorOr_Types_Test::TestBody() { | ||
45 | int x; | ||
46 | ErrorOr<int&> a(x); | ||
47 | *a = 42; | ||
48 | EXPECT_EQ(42, x)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(42)) == 1)>::Compare("42", "x", 42, x))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn255820/unittests/Support/ErrorOrTest.cpp" , 48, gtest_ar.failure_message()) = ::testing::Message(); | ||
49 | |||
50 | // Move only types. | ||
51 | EXPECT_EQ(3, **t3())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(3)) == 1)>::Compare("3", "**t3()" , 3, **t3()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn255820/unittests/Support/ErrorOrTest.cpp" , 51, gtest_ar.failure_message()) = ::testing::Message(); | ||
52 | } | ||
53 | |||
54 | struct B {}; | ||
55 | struct D : B {}; | ||
56 | |||
57 | TEST(ErrorOr, Covariant)class ErrorOr_Covariant_Test : public ::testing::Test { public : ErrorOr_Covariant_Test() {} private: virtual void TestBody( ); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ErrorOr_Covariant_Test(ErrorOr_Covariant_Test const &); void operator=(ErrorOr_Covariant_Test const &);} ;::testing::TestInfo* const ErrorOr_Covariant_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ErrorOr", "Covariant" , __null, __null, (::testing::internal::GetTestTypeId()), ::testing ::Test::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing::internal::TestFactoryImpl< ErrorOr_Covariant_Test >);void ErrorOr_Covariant_Test::TestBody() { | ||
58 | ErrorOr<B*> b(ErrorOr<D*>(nullptr)); | ||
59 | b = ErrorOr<D*>(nullptr); | ||
60 | |||
61 | ErrorOr<std::unique_ptr<B> > b1(ErrorOr<std::unique_ptr<D> >(nullptr)); | ||
62 | b1 = ErrorOr<std::unique_ptr<D> >(nullptr); | ||
63 | |||
64 | ErrorOr<std::unique_ptr<int>> b2(ErrorOr<int *>(nullptr)); | ||
65 | ErrorOr<int *> b3(nullptr); | ||
66 | ErrorOr<std::unique_ptr<int>> b4(b3); | ||
67 | } | ||
68 | |||
69 | TEST(ErrorOr, Comparison)class ErrorOr_Comparison_Test : public ::testing::Test { public : ErrorOr_Comparison_Test() {} private: virtual void TestBody (); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ErrorOr_Comparison_Test(ErrorOr_Comparison_Test const &); void operator=(ErrorOr_Comparison_Test const &); };::testing::TestInfo* const ErrorOr_Comparison_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ErrorOr", "Comparison" , __null, __null, (::testing::internal::GetTestTypeId()), ::testing ::Test::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing::internal::TestFactoryImpl< ErrorOr_Comparison_Test >);void ErrorOr_Comparison_Test::TestBody() { | ||
70 | ErrorOr<int> x(errc::no_such_file_or_directory); | ||
71 | EXPECT_EQ(x, errc::no_such_file_or_directory)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(x)) == 1)>::Compare("x", "errc::no_such_file_or_directory" , x, errc::no_such_file_or_directory))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn255820/unittests/Support/ErrorOrTest.cpp" , 71, gtest_ar.failure_message()) = ::testing::Message(); | ||
72 | } | ||
73 | |||
74 | // ErrorOr<int*> x(nullptr); | ||
75 | // ErrorOr<std::unique_ptr<int>> y = x; // invalid conversion | ||
76 | static_assert( | ||
77 | !std::is_convertible<const ErrorOr<int *> &, | ||
78 | ErrorOr<std::unique_ptr<int>>>::value, | ||
79 | "do not invoke explicit ctors in implicit conversion from lvalue"); | ||
80 | |||
81 | // ErrorOr<std::unique_ptr<int>> y = ErrorOr<int*>(nullptr); // invalid | ||
82 | // // conversion | ||
83 | static_assert( | ||
84 | !std::is_convertible<ErrorOr<int *> &&, | ||
85 | ErrorOr<std::unique_ptr<int>>>::value, | ||
86 | "do not invoke explicit ctors in implicit conversion from rvalue"); | ||
87 | |||
88 | // ErrorOr<int*> x(nullptr); | ||
89 | // ErrorOr<std::unique_ptr<int>> y; | ||
90 | // y = x; // invalid conversion | ||
91 | static_assert(!std::is_assignable<ErrorOr<std::unique_ptr<int>>, | ||
92 | const ErrorOr<int *> &>::value, | ||
93 | "do not invoke explicit ctors in assignment"); | ||
94 | |||
95 | // ErrorOr<std::unique_ptr<int>> x; | ||
96 | // x = ErrorOr<int*>(nullptr); // invalid conversion | ||
97 | static_assert(!std::is_assignable<ErrorOr<std::unique_ptr<int>>, | ||
98 | ErrorOr<int *> &&>::value, | ||
99 | "do not invoke explicit ctors in assignment"); | ||
100 | } // end anon namespace |