Replace GTEST_AMBIGUOUS_ELSE_BLOCKER_ #2431
Closed
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.
with for loops and (where necessary) lambdas.
Fixes #1119. Requires C++11.
For example, replace:
with:
This allows the user to continue to stream more information into the violation message, and avoids the "dangling else" warning-error since we aren't using any if/else statements.
If the predicate or any branches are more complicated than a single statement-expression, use a lambda; this requires C++11. This is necessary for death, throw, no-throw, and no-fatal-failure checks. As a result:
return
(includingGTEST_FAIL
andGTEST_SKIP
) from within the test statement is a runtime error.return
from within the test statement is typically a compile error, but might not be if the user accidentally returns a compatible type. It would be possible to prevent this, or make it a runtime error.GTEST_FAIL
andGTEST_SKIP
are always a compile error, but could be changed to a runtime error.EXPECT_NO_FATAL_FAILURE(FAIL())
) no longer abort the containing test. TestNoFatalFailureTest.MessageIsStreamable
is modified accordingly; previously, it was broken as none of the checks within the test function (afterEXPECT_NO_FATAL_FAILURE(FAIL())
) ran. Other return statements (includingGTEST_SKIP
) are ignored; this could be changed to a runtime error.Finally: remove the
-Werror=dangling-else
suppression, since it isn't required any more.