Evaluate CHECK_COMPARE operands once and honor location - #1895
Open
Angel2Eyes wants to merge 1 commit into
Open
Angel2Eyes wants to merge 1 commit into
Angel2Eyes wants to merge 1 commit into
Conversation
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]>
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CHECK_COMPAREoperands once withconst auto&whenautois available, so side-effecting expressions are not run again to build the failure message.fileandlinearguments through toassertCompareinstead of__FILE__/__LINE__fromUtestMacros.h.Problem
CHECK_COMPARE_LOCATIONpasted each operand into the comparison and again intoStringFrom(...). On failure,CHECK_COMPARE(nextId(), <, 10)callednextId()twice: the compare used one value and the message printed another. That is #1488.The same macro ignored its
fileandlineparameters and always reportedUtestMacros.h. Wrappers built onCHECK_COMPARE_LOCATIONcould not point at the call site.Fix
When
CPPUTEST_HAVE_AUTO_TYPEis set (C++11, or MSVC 2010+ using the same detection asNULLPTR), bindconst auto&copies and compare / stringify those.const auto&rather thanauto&&so bitfields still compile. C++98 keeps the old evaluation path so that CI job still builds, but it does honorfileandline.Verification
countingMethod_()printsCHECK_COMPARE(0 > 100)and increments the counter once (C++11+).CHECK_COMPARE_LOCATION(..., "wrapper.cpp", 1234)reports that file and line.CHECK_COMPAREon bitfield members compiles and passes.