aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Michael Wyman <michael@mwyman.com>2020-01-21 09:18:29 -0800
committerGravatar Thomas Van Lenten <thomasvl@google.com>2020-01-21 15:29:40 -0500
commit074577c360568871b35834bbbc73bfd05305589e (patch)
treecb59e9ffd73e68b337391227c2080e5bc8f3fd73
parentb504474033b466ddda28ad3b3557f78004522d82 (diff)
Avoid nullability compiler/clang-tidy warnings in _GTMDevAssert.
The string parameters in NSAssertionHandler's -handleFailureInFunction:… method are declared nonnull, but converting __PRETTY_FUNCTION__ and __FILE__ to NSString (via +[NSString stringWithUTF8String:] returns nullable, leading to warnings.
-rw-r--r--GTMDefines.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/GTMDefines.h b/GTMDefines.h
index 68ff8c0..f2c047e 100644
--- a/GTMDefines.h
+++ b/GTMDefines.h
@@ -130,11 +130,16 @@
#if !defined(NS_BLOCK_ASSERTIONS)
#define _GTMDevAssert(condition, ...) \
do { \
- if (!(condition)) { \
+ if (__builtin_expect(!(condition), 0)) { \
+ NSString *__assert_func_name__ = \
+ [NSString stringWithUTF8String:__PRETTY_FUNCTION__]; \
+ __assert_func_name__ = __assert_func_name__ ?: @"<Unknown Function>"; \
+ NSString *__assert_file_name__ = \
+ [NSString stringWithUTF8String:__FILE__]; \
+ __assert_file_name__ = __assert_file_name__ ?: @"<Unknown File>"; \
[[NSAssertionHandler currentHandler] \
- handleFailureInFunction:(NSString *) \
- [NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
- file:(NSString *)[NSString stringWithUTF8String:__FILE__] \
+ handleFailureInFunction:__assert_func_name__ \
+ file:__assert_file_name__ \
lineNumber:__LINE__ \
description:__VA_ARGS__]; \
} \