[cfe-dev] clang-format and BSD KNF

Daniel Dilts diltsman at outlook.com
Wed Jun 11 11:25:44 PDT 2014


> For example:
> 
>   int foo(int i);
> 
>   int
>   foo(int i)
>   {
>>   }
> 
> I’m having trouble distinguishing between function prototypes and definitions.

 


I doubt that it is possible to distinguish between these cases.  clang-format works on a stream of tokens, not the AST.  I do not believe that there is any reliable way to distinguish between function prototypes and definitions without at least a partial AST. Why not? One ends in a semicolon, the other in an open curly brace. clang-format has to make basically all of its decisions this way.. In the general case this would require infinite lookahead.  A function can have n parameters, each with a set of attributes.  I don't know if lookahead is supported in clang-format, so I won't comment on that. The one case that I don't think is possible to do without some AST based information is to disambiguate variations of the most vexing parse. class C{};C c;int func1(C);C func2(c); Without knowing that C is a type and c is a variable you cannot decide that func1 is a function declaration and func2 is a variable definition. 		 	   		   		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140611/6c808504/attachment.html>


More information about the cfe-dev mailing list