llvm-gcc fails to recognize __block keywords
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
llvm-gcc-4.2 (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: llvm-gcc-4.2
the following source code:
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
#ifdef __BLOCKS__
int closed = 1;
__block int open = 2;
//int open = 2;
void (^print)(int) = ^(int n)
{
printf("%d %d %d\n", closed, open, n);
};
closed = 3;
open = 4;
print(5); // prints 1 4 5
#endif
return 0;
}
compiled with:
/usr/lib/
causes:
blocks.c: In function 'main':
blocks.c:9: error: '__block' undeclared (first use in this function)
blocks.c:9: error: (Each undeclared identifier is reported only once
blocks.c:9: error: for each function it appears in.)
blocks.c:9: error: expected ';' before 'int'
blocks.c: In function '__main_
blocks.c:13: error: 'open' undeclared (first use in this function)
blocks.c: In function 'main':
blocks.c:17: error: 'open' undeclared (first use in this function)
after removing the __block keyword, compilation succeeds. (links and runs fine as well
after manually compiling the blocks runtime library.)
for reference:
> /usr/lib/
llvm-gcc (GCC) 4.2.1 (Based on Apple Inc. build 5649) (LLVM build)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> apt-cache policy llvm-gcc-4.2
llvm-gcc-4.2:
Installed: 2.6~pre1-0ubuntu1
Candidate: 2.6~pre1-0ubuntu1
Version table:
*** 2.6~pre1-0ubuntu1 0
500 http://
100 /var/lib/
looking at the LLVM/Clang documentation (http:// clang.llvm. org/doxygen/ InitPreprocesso r_8cpp- source. html) shows that __block is not actually a keyword, but a macro that is defined to be __attribute_ _((__blocks_ _(byref) )).
so adding:
#ifndef __block _((__blocks_ _(byref) ))
#define __block __attribute_
#endif
to the above example works.
btw: this also happens if using a self-compiled upstream LLVM/GCC, so it's not actually an Ubuntu bug.