Reviewers: Jeffrey Yasskin, Zhanyong Wan,
Message:
Hey,
When working on googletest, this warning spews like crazy from Clang. We
discussed making the warning detect goto/label edges and behave
correctly, but it complicates the warning and would likely slow down
Clang to do this.
At first, I suspected it would be really hard to re-write this macros to
avoid the warning, but I got the idea to just add a layer between the
variable declaring if-statement and the control-flow managing
if-statement. It might be possible to factor this more, but I'm not sure
it's worth it.
Thoughts?
Please review this at
http://codereview.appspot.com/1175041/show
Affected files:
M include/gtest/internal/gtest-internal.h
Index: include/gtest/internal/gtest-internal.h
===================================================================
--- include/gtest/internal/gtest-internal.h (revision 423)
+++ include/gtest/internal/gtest-internal.h (working copy)
@@ -808,7 +808,9 @@
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
- if (const char* gtest_msg = "") { \
+ if (const char* gtest_msg = "") \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (true) { \
bool gtest_caught_expected = false; \
try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
@@ -833,7 +835,9 @@
#define GTEST_TEST_NO_THROW_(statement, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
- if (const char* gtest_msg = "") { \
+ if (const char* gtest_msg = "") \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (true) { \
try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} \
@@ -848,7 +852,9 @@
#define GTEST_TEST_ANY_THROW_(statement, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
- if (const char* gtest_msg = "") { \
+ if (const char* gtest_msg = "") \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (true) { \
bool gtest_caught_any = false; \
try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
@@ -880,7 +886,9 @@
#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
- if (const char* gtest_msg = "") { \
+ if (const char* gtest_msg = "") \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (true) { \
::testing::internal::HasNewFatalFailureHelper
gtest_fatal_failure_checker; \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \