mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 15:21:54 +00:00
Fix dangling else problem in FMT_ASSERT
This commit is contained in:
parent
fafb03fa6d
commit
6037b3cae9
@ -231,8 +231,9 @@ void assert_fail(const char* file, int line, const char* message);
|
|||||||
# define FMT_ASSERT(condition, message)
|
# define FMT_ASSERT(condition, message)
|
||||||
# else
|
# else
|
||||||
# define FMT_ASSERT(condition, message) \
|
# define FMT_ASSERT(condition, message) \
|
||||||
if (!(condition)) \
|
((condition) \
|
||||||
fmt::internal::assert_fail(__FILE__, __LINE__, (message))
|
? void() \
|
||||||
|
: fmt::internal::assert_fail(__FILE__, __LINE__, (message)))
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -20,3 +20,14 @@ TEST(AssertTest, Fail) {
|
|||||||
EXPECT_DEBUG_DEATH_IF_SUPPORTED(FMT_ASSERT(false, "don't panic!"),
|
EXPECT_DEBUG_DEATH_IF_SUPPORTED(FMT_ASSERT(false, "don't panic!"),
|
||||||
"don't panic!");
|
"don't panic!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool test_condition = false;
|
||||||
|
|
||||||
|
TEST(AssertTest, DanglingElse) {
|
||||||
|
bool executed_else = false;
|
||||||
|
if (test_condition)
|
||||||
|
FMT_ASSERT(true, "");
|
||||||
|
else
|
||||||
|
executed_else = true;
|
||||||
|
EXPECT_TRUE(executed_else);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user