<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>> For example:<br>> <br>> int foo(int i);<br>> <br>> int<br>> foo(int i)<br>> {<br>> …<br>> }<br>> <br>> I’m having trouble distinguishing between function prototypes and definitions.<br>
<br><br><BR><div><div dir="ltr"><div><div dir="ltr"><div class="ecxgmail_extra"><div class="ecxgmail_quote"><blockquote class="ecxgmail_quote" style="padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"><div><div dir="ltr">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.</div><div dir="ltr"> </div><div dir="ltr">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..</div></div></blockquote><div> </div><div>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.</div><div> </div><div>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.</div><div> </div><div>class C{};</div><div>C c;</div><div>int func1(C);</div><div>C func2(c);</div><div> </div><div>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.</div></div></div></div></div> </div></div> </div></body>
</html>