【发布时间】:2020-08-07 11:33:23
【问题描述】:
#include <stdio.h>
#include <Block.h>
int main()
{
__block int x = 5;
^{printf("x is %i\n", x);}();
}
当我使用 clang 编译一个同时使用 clang 块和 __block 类型说明符的 c(或 c++)程序时,即使使用 -Wall 和 -Wpedantic,也不会产生编译器警告。该程序也按预期运行。但是,如果我使用文本编辑器打开可执行文件,我会找到这段文本(使用“字符串”命令提取):
Block_release called upon a stack Block: %p, ignored
_Block_byref_release: Block byref data structure at %p underflowed
Block compiled by obsolete compiler, please recompile source for this Block
descriptor->dispose helper: %p
byref data block %p contents:
^%p (new layout) =
isa?: %p
refcount: %u
invoke: %p
descriptor: %p
descriptor->reserved: %lu
descriptor->size: %lu
descriptor->copy helper: %p
forwarding: %p
flags: 0x%x
size: %d
copy helper: %p
dispose helper: %p
NULL passed to _isa: stack Blockisa: malloc heapisa: GC heap Bloisa: global Blocisa: finalizing
问题是我使用的是最新版本的 clang - 几乎不是“过时”的编译器。我在 Linux (musl) 上,我从 https://github.com/mackyle/blocksruntime 安装了 BlocksRuntime。我还在这里找到了生成警告的代码-https://github.com/mackyle/blocksruntime/blob/master/BlocksRuntime/runtime.c#L629
λ: clang --version
clang version 10.0.0
Target: x86_64-unknown-linux-musl
Thread model: posix
InstalledDir: /bin
λ: uname -a
Linux thinkpad 5.7.9_1 #1 SMP Thu Jul 16 10:02:50 UTC 2020 x86_64 GNU/Linux
忽略此警告是否安全?如果没有,我该怎么办?
【问题讨论】:
标签: c++ c clang objective-c-blocks clang++