From 554c688ebabed659a7c8d09c917d938ffe772eb3 Mon Sep 17 00:00:00 2001 From: Brandon Kase Date: Fri, 7 Jul 2017 16:29:50 -0700 Subject: [PATCH] Workaround clang4.0 initialization (#426) Texture fails to build with this error on clang 4.0: ``` external/Texture/pod_support/Headers/Public/AsyncDisplayKit/ASDispatch.h:32:35: error: illegal initializer type 'atomic_size_t' (aka '_Atomic(size_t)') __block atomic_size_t counter = ATOMIC_VAR_INIT(0); ^ In module 'std' imported from external/Texture/pod_support/Headers/Public/AsyncDisplayKit/ASStackUnpositionedLayout.h:18: /private/var/tmp/_bazel_bkase/a00d4cbe29902fb63d5778cc19944cd2/external/clang40/bin/../include/c++/v1/atomic:1839:30: note: expanded from macro 'ATOMIC_VAR_INIT' ^ 1 error generated. ``` See http://techqa.info/programming/question/38233019/Initializing-an--atomic-int--with-a-braced-constant--Is-this-valid-C-code--If-so-why-does-it-not-compile-in-clang- Replacing the intialization with just 0 (and not the macro fixes the error). For now this is safe because the macro just expands to the value. --- Source/Private/ASDispatch.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Private/ASDispatch.h b/Source/Private/ASDispatch.h index 811dc44658..c0a14c77d9 100644 --- a/Source/Private/ASDispatch.h +++ b/Source/Private/ASDispatch.h @@ -29,7 +29,12 @@ static void ASDispatchApply(size_t iterationCount, dispatch_queue_t queue, NSUIn threadCount = NSProcessInfo.processInfo.activeProcessorCount * 2; } dispatch_group_t group = dispatch_group_create(); - __block atomic_size_t counter = ATOMIC_VAR_INIT(0); + // HACK: This is a workaround for mm files that include this in Clang4.0 + // Omitting ATOMIC_VAR_INIT is okay in this case because the current + // expansion of that macro no-ops. + // TODO: Move this implementation into a m file so it's not compiled in C++ + // See: https://github.com/TextureGroup/Texture/pull/426 + __block atomic_size_t counter = 0; for (NSUInteger t = 0; t < threadCount; t++) { dispatch_group_async(group, queue, ^{ size_t i;