The parser currently looks for return bounds declarations as part of function declarators. They optionally appear after the argument list. For C functions that return constructed types that are complex, it is easy to get confused about this subtlety. One might think that the return bounds declaration appear after the declarator for a function and before the body.
Here is an example of a function that returns an unchecked pointer to 10 element array:
int (*(r31(int arg[10][10])))[10] {
return arg;
}
If we want to add a bounds interop declaration to this complex declarator, the correct way to write it is:
int (*(r31(int arg[10][10]) : count(10)))[10] {
return arg;
}
An incorrect way to write this is:
int (*(r31e(int arg[10][10])))[10] : count(10) {
return arg;
}:
This results in the not-very-helpful error message:
expected function body after function declarator
We should improve the error message for this situation in clang. This is an easy error to make. In addition, it would be helpful to clearly document in the Checked C language extension that for function return values, the bounds declaration is part of the function declarator.
Note that this odd case is really a result of the complex way that return types for functions are declared in C. This case doesn't happen when using the new checked types. Instead one has
ptr<int[10]> r31(int arg[10][10]) {
return arg;
}