Changes imported from Abseil "staging" branch:
- 95e20a66bfa6104937ec92722b04a9c0ca0443dc Make ThrowingBool convertible to bool. by Xiaoyi Zhang <zhangxy@google.com> GitOrigin-RevId: 95e20a66bfa6104937ec92722b04a9c0ca0443dc Change-Id: I7a1dcb53b0764b24482ee1886276b267c8cb83c2
This commit is contained in:
		
							parent
							
								
									2661ed4998
								
							
						
					
					
						commit
						eed36bfba0
					
				
					 2 changed files with 18 additions and 3 deletions
				
			
		|  | @ -18,6 +18,7 @@ | ||||||
| #include <exception> | #include <exception> | ||||||
| #include <iostream> | #include <iostream> | ||||||
| #include <list> | #include <list> | ||||||
|  | #include <type_traits> | ||||||
| #include <vector> | #include <vector> | ||||||
| 
 | 
 | ||||||
| #include "gtest/gtest-spi.h" | #include "gtest/gtest-spi.h" | ||||||
|  | @ -683,6 +684,18 @@ TEST(AllocInspectorTest, ConstructedTwice) { | ||||||
|         new (&storage) Tracked; |         new (&storage) Tracked; | ||||||
|       }, |       }, | ||||||
|       "re-constructed"); |       "re-constructed"); | ||||||
|  |   reinterpret_cast<Tracked*>(&storage)->~Tracked(); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | TEST(ThrowingValueTraitsTest, RelationalOperators) { | ||||||
|  |   ThrowingValue<> a, b; | ||||||
|  |   EXPECT_TRUE((std::is_convertible<decltype(a == b), bool>::value)); | ||||||
|  |   EXPECT_TRUE((std::is_convertible<decltype(a != b), bool>::value)); | ||||||
|  |   EXPECT_TRUE((std::is_convertible<decltype(a < b), bool>::value)); | ||||||
|  |   EXPECT_TRUE((std::is_convertible<decltype(a <= b), bool>::value)); | ||||||
|  |   EXPECT_TRUE((std::is_convertible<decltype(a > b), bool>::value)); | ||||||
|  |   EXPECT_TRUE((std::is_convertible<decltype(a >= b), bool>::value)); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| }  // namespace
 | }  // namespace
 | ||||||
| }  // namespace absl
 | }  // namespace absl
 | ||||||
|  |  | ||||||
|  | @ -203,12 +203,12 @@ extern exceptions_internal::NoThrowTag no_throw_ctor; | ||||||
| inline void SetCountdown() { exceptions_internal::countdown = 0; } | inline void SetCountdown() { exceptions_internal::countdown = 0; } | ||||||
| inline void UnsetCountdown() { exceptions_internal::countdown = -1; } | inline void UnsetCountdown() { exceptions_internal::countdown = -1; } | ||||||
| 
 | 
 | ||||||
| // A test class which is contextually convertible to bool.  The conversion can
 | // A test class which is convertible to bool.  The conversion can be
 | ||||||
| // be instrumented to throw at a controlled time.
 | // instrumented to throw at a controlled time.
 | ||||||
| class ThrowingBool { | class ThrowingBool { | ||||||
|  public: |  public: | ||||||
|   ThrowingBool(bool b) noexcept : b_(b) {}  // NOLINT(runtime/explicit)
 |   ThrowingBool(bool b) noexcept : b_(b) {}  // NOLINT(runtime/explicit)
 | ||||||
|   explicit operator bool() const { |   operator bool() const {  // NOLINT(runtime/explicit)
 | ||||||
|     exceptions_internal::MaybeThrow(ABSL_PRETTY_FUNCTION); |     exceptions_internal::MaybeThrow(ABSL_PRETTY_FUNCTION); | ||||||
|     return b_; |     return b_; | ||||||
|   } |   } | ||||||
|  | @ -355,6 +355,8 @@ class ThrowingValue : private exceptions_internal::TrackedObject { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // Comparison Operators
 |   // Comparison Operators
 | ||||||
|  |   // NOTE: We use `ThrowingBool` instead of `bool` because most STL
 | ||||||
|  |   // types/containers requires T to be convertible to bool.
 | ||||||
|   friend ThrowingBool operator==(const ThrowingValue& a, |   friend ThrowingBool operator==(const ThrowingValue& a, | ||||||
|                                  const ThrowingValue& b) { |                                  const ThrowingValue& b) { | ||||||
|     exceptions_internal::MaybeThrow(ABSL_PRETTY_FUNCTION); |     exceptions_internal::MaybeThrow(ABSL_PRETTY_FUNCTION); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue