diff options
author | Michael Wyman <michael@mwyman.com> | 2020-01-21 09:18:29 -0800 |
---|---|---|
committer | Thomas Van Lenten <thomasvl@google.com> | 2020-01-21 15:29:40 -0500 |
commit | 074577c360568871b35834bbbc73bfd05305589e (patch) | |
tree | cb59e9ffd73e68b337391227c2080e5bc8f3fd73 | |
parent | b504474033b466ddda28ad3b3557f78004522d82 (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.h | 13 |
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__]; \ } \ |