One blog related to Block of Objective-C says: when ARC enabled, the following codes:
typedef int (^blk_t)(int);
blk_t func(int rate)
{
return ^(int count){return rate * count;};
}
can be translated into C++ codes as below with the -rewrite-objc of clang:
blk_t func(int rate)
{
blk_t tmp = &__func_block_impl_0(__func_block_func_0, &__func_block_desc_0_DATA, rate);
tmp = objc_retainBlock(tmp);
return objc_autoreleaseReturnValue(tmp);
}
I tried do the translation with the following ways, but not succeed.
- clang -rewrite-objc test.m --> This command can translate the test.m to cpp codes. But I cannot see the calling of objc_retainBlock and objc_autoreleaseReturnValue.
- clang -rewrite-objc -fobjc-arc test.m -> This command will fail with "error: the current deployment target does not support automated __weak references". In results, the cpp codes are not generated.
- clang -rewrite-objc -fobjc-arc -mmacosx-version-min=10.11 test.m, the behaviour is same as #2.
Question: How can I translate the ARC enabled Objective-C codes to cpp with the option -rewrite-objc of clang?
At last, I found the missing clang option: -fobjc-runtime; the rewrite works after specify the objc-runtime version. For example the following command: