Fix mistake in Language Specification for Blocks

Peter Cawley corsix at corsix.org
Mon Feb 16 04:34:40 PST 2015


The Language Specification for Blocks, as published at
http://clang.llvm.org/docs/BlockLanguageSpec.html, currently claims
that `^ int ((*)(float x))(char) { return functionPointer; }` is valid
syntax, and is equivalent to other valid syntax. I doubt that this was
ever the case, and it certainly isn't the case currently:

```
[littlegate /Users/corsix]$ cat test.cpp
int main() {
  int (*functionPointer)(char) = 0;
  auto b = ^ int ((*)(float x))(char) { return functionPointer; };
}
[littlegate /Users/corsix]$ clang -std=c++11 test.cpp
test.cpp:3:22: error: function cannot return function type 'int (char)'
  auto b = ^ int ((*)(float x))(char) { return functionPointer; };
                     ^
test.cpp:3:48: error: cannot initialize return object of type 'int
(*)(float)' with an lvalue of type 'int (*const)(char)': type mismatch
at 1st parameter ('float' vs 'char')
  auto b = ^ int ((*)(float x))(char) { return functionPointer; };
                                               ^~~~~~~~~~~~~~~
2 errors generated.
```

The attached patch changes the documentation to what I think was
meant, which seems to compile cleanly:

```
[littlegate /Users/corsix]$ cat test.cpp
int main() {
  int (*functionPointer)(char) = 0;
  auto b = ^ int (*(float x))(char) { return functionPointer; };
}
[littlegate /Users/corsix]$ clang -std=c++11 test.cpp && echo No Errors
No Errors
```
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BlockLanguageSpec.rst.patch
Type: application/octet-stream
Size: 398 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150216/6c9e6831/attachment.obj>


More information about the cfe-commits mailing list