-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Description
Describe the issue
Values supporting boolean evaluation (e.g. with operator bool()) display differing behavior between ASSERT_TRUE and ASSERT_FALSE dependent on constness, as ASSERT_TRUE enforces constness and ASSERT_FALSE does not propagate it. This is especially problematic where the object is of a type that has both not const (e.g. operator bool()) and const (e.g. operator bool() const) operations defined with different functionality.
Specfically, via AssertionResult:
ASSERT_TRUE:
- Accepts a const reference to a value
- Evaluates the reference to a boolean
- Assigns the result to its
success_value.
ASSERT_FALSE:
- Evaluates a value to a boolean
- Accepts boolean as a const reference
- Assigns the result to its
success_value.
The macro GTEST_EXPECT_FALSE is used by the ASSERT_FALSE macro, but this forces evaluation to a boolean without enforcing or propagating constness, leading to the differences behavior.
Steps to reproduce the problem
I have included a demonstration test showing the problem in isolation, and I have included a simple CMakeLists.txt . This should also show that the problem is simple to reproduce.
What version of GoogleTest are you using?
v1.17.0
What operating system and version are you using?
Linux
What compiler and version are you using?
gcc 15.2.0
What build system are you using?
cmake
Additional context
No response