浏览代码

Merge pull request #1034 from thomasvl/static_assert_fix

Use compiler provided static assert and avoid tripping unused-local-typedef warnings.
Thomas Van Lenten 9 年之前
父节点
当前提交
46be1d06f5
共有 1 个文件被更改,包括 9 次插入4 次删除
  1. 9 4
      objectivec/GPBMessage.m

+ 9 - 4
objectivec/GPBMessage.m

@@ -55,10 +55,15 @@ NSString *const GPBExceptionMessageKey =
 static NSString *const kGPBDataCoderKey = @"GPBData";
 static NSString *const kGPBDataCoderKey = @"GPBData";
 
 
 #ifndef _GPBCompileAssert
 #ifndef _GPBCompileAssert
-#define _GPBCompileAssertSymbolInner(line, msg) _GPBCompileAssert ## line ## __ ## msg
-#define _GPBCompileAssertSymbol(line, msg) _GPBCompileAssertSymbolInner(line, msg)
-#define _GPBCompileAssert(test, msg) \
-    typedef char _GPBCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ]
+  #if __has_feature(c_static_assert) || __has_extension(c_static_assert)
+    #define _GPBCompileAssert(test, msg) _Static_assert((test), #msg)
+  #else
+    // Pre-Xcode 7 support.
+    #define _GPBCompileAssertSymbolInner(line, msg) _GPBCompileAssert ## line ## __ ## msg
+    #define _GPBCompileAssertSymbol(line, msg) _GPBCompileAssertSymbolInner(line, msg)
+    #define _GPBCompileAssert(test, msg) \
+        typedef char _GPBCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ]
+  #endif  // __has_feature(c_static_assert) || __has_extension(c_static_assert)
 #endif // _GPBCompileAssert
 #endif // _GPBCompileAssert
 
 
 //
 //