Skip to content

Commit 7e62c36

Browse files
wilhuffa-maurice
authored andcommitted
Avoid empty statement warnings in Firebase assertions
Wrapping macro bodies in do { } while(false) makes them into a statement that legitimately should be followed by a semicolon. PiperOrigin-RevId: 320272779
1 parent a70101c commit 7e62c36

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

app/src/assert.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545
// Assert condition is true, if it's false log an assert with the specified
4646
// expression as a string.
4747
#define FIREBASE_ASSERT_WITH_EXPRESSION(condition, expression) \
48-
{ \
48+
do { \
4949
if (!(condition)) { \
50-
FIREBASE_NAMESPACE::LogAssert( \
50+
FIREBASE_NAMESPACE::LogAssert( \
5151
FIREBASE_ASSERT_MESSAGE_PREFIX FIREBASE_EXPAND_STRINGIFY( \
5252
expression)); \
5353
} \
54-
}
54+
} while (false)
5555

5656
// Assert condition is true, if it's false log an assert with the specified
5757
// expression as a string. Compiled out of release builds.
@@ -60,7 +60,7 @@
6060
FIREBASE_ASSERT_WITH_EXPRESSION(condition, expression)
6161
#else
6262
#define FIREBASE_DEV_ASSERT_WITH_EXPRESSION(condition, expression) \
63-
{ (void)(condition); }
63+
(void)(condition)
6464
#endif // !defined(NDEBUG)
6565

6666
// Custom assert() implementation that is not compiled out in release builds.
@@ -111,14 +111,14 @@
111111
// Assert condition is true otherwise display the specified expression,
112112
// message and abort.
113113
#define FIREBASE_ASSERT_MESSAGE_WITH_EXPRESSION(condition, expression, ...) \
114-
{ \
114+
do { \
115115
if (!(condition)) { \
116-
FIREBASE_NAMESPACE::LogError( \
116+
FIREBASE_NAMESPACE::LogError( \
117117
FIREBASE_ASSERT_MESSAGE_PREFIX FIREBASE_EXPAND_STRINGIFY( \
118118
expression)); \
119-
FIREBASE_NAMESPACE::LogAssert(__VA_ARGS__); \
119+
FIREBASE_NAMESPACE::LogAssert(__VA_ARGS__); \
120120
} \
121-
}
121+
} while (false)
122122

123123
// Assert condition is true otherwise display the specified expression,
124124
// message and abort. Compiled out of release builds.

database/src/desktop/persistence/prune_forest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const PruneForestRef PruneForestRef::GetChild(const Path& path) const {
7979
void PruneForestRef::Prune(const Path& path) {
8080
FIREBASE_DEV_ASSERT_MESSAGE(
8181
prune_forest_->RootMostValueMatching(path, KeepPredicate) == nullptr,
82-
"Can't prune path that was kept previously!")
82+
"Can't prune path that was kept previously!");
8383
if (prune_forest_->RootMostValueMatching(path, PrunePredicate) != nullptr) {
8484
// This path will already be pruned
8585
} else {

0 commit comments

Comments
 (0)