Skip to content

[Bug]: ASSERT_FALSE and ASSERT_TRUE const propagation inconsistencies lead to differing failure results #4832

@yardswp

Description

@yardswp

CMakeLists.txt

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.

example.cpp

CMakeLists.txt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions