Skip to content

Evaluate CHECK_COMPARE operands once and honor location - #1895

Open
Angel2Eyes wants to merge 1 commit into
cpputest:masterfrom
Angel2Eyes:fix/check-compare-eval-once
Open

Angel2Eyes wants to merge 1 commit into
cpputest:masterfrom
Angel2Eyes:fix/check-compare-eval-once

Conversation

@Angel2Eyes

Copy link
Copy Markdown

Summary

  • Capture CHECK_COMPARE operands once with const auto& when auto is available, so side-effecting expressions are not run again to build the failure message.
  • Pass the file and line arguments through to assertCompare instead of __FILE__ / __LINE__ from UtestMacros.h.

Problem

CHECK_COMPARE_LOCATION pasted each operand into the comparison and again into StringFrom(...). On failure, CHECK_COMPARE(nextId(), <, 10) called nextId() twice: the compare used one value and the message printed another. That is #1488.

The same macro ignored its file and line parameters and always reported UtestMacros.h. Wrappers built on CHECK_COMPARE_LOCATION could not point at the call site.

Fix

When CPPUTEST_HAVE_AUTO_TYPE is set (C++11, or MSVC 2010+ using the same detection as NULLPTR), bind const auto& copies and compare / stringify those. const auto& rather than auto&& so bitfields still compile. C++98 keeps the old evaluation path so that CI job still builds, but it does honor file and line.

Verification

  • Failure with countingMethod_() prints CHECK_COMPARE(0 > 100) and increments the counter once (C++11+).
  • CHECK_COMPARE_LOCATION(..., "wrapper.cpp", 1234) reports that file and line.
  • CHECK_COMPARE on bitfield members compiles and passes.
  • CMake/CTest RelWithDebInfo on MSVC: 84/84 passed.

CHECK_COMPARE_LOCATION pasted both operands into the
failure message, so side effects ran twice. It also
ignored its file and line arguments. Capture with
const auto& when auto is available, and always pass
file and line through.

Fixes cpputest#1488

Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant