<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Dear Clang Community,<div class=""><br class=""></div><div class="">TL:DR; If at all possible, how can I wrangle clang-format to give me:</div><div class=""><br class=""></div><div class="">1. The following as one line</div><div class=""><br class=""></div><div class="">ierr = FunctionCall();CHKERRQ(ierr);</div><div class=""><br class=""></div><div class="">And not</div><div class=""><br class=""></div><div class="">ierr = FunctionCall();</div><div class="">CHKERRQ(ierr);</div><div class=""><br class=""></div><div class="">2. Function parameters without spaces:</div><div class=""><br class=""></div><div class="">FunctionCall(a,b,c);</div><div class=""><br class=""></div><div class="">And not</div><div class=""><br class=""></div><div class="">FunctionCall(a, b, c);</div><div class=""><br class=""></div><div class="">No holds barred here, modifying clang-format internals/providing patches is not off the table.</div><div class=""><br class=""></div><div class="">————————————</div><div class=""><br class=""></div><div class="">I am a contributor to the Portable Extensible Toolkit for Scientific Computation (PETSc), and have been trying to modernize the tooling workflow within PETSc using clang-tooling. I’ve had great success implementing a linter using the libclang python interface so style enforcement was next on the chopping block.</div><div class=""><br class=""></div><div class="">Like any established code-base we have an opinionated code-style (<a href="https://petsc.org/release/developers/style/" class="">https://petsc.org/release/developers/style/</a>) which is absolutely powerless against the developer that doesn’t read it. So far we’ve painstakingly enforced it by judicious grep-based checkers (or by hand in code-review :( ). We’d love to use clang-format to automate this but have 2 main sticking points:</div><div class=""><br class=""></div><div class="">1. An error-code checking macro:</div><div class=""><br class=""></div><div class=""><div class="">#define CHKERRQ(ierr) do {  \</div><div class="">    if (ierr) {             \</div><div class="">      handleError(ierr);    \</div><div class="">    }                       \</div><div class="">  } while (0)</div></div><div class=""><br class=""></div><div class="">Which is appended to every line, and *must* be on the same line as the call:</div><div class=""><br class=""></div><div class="">ierr = LibraryFunctionCall();CHKERRQ(ierr);</div><div class=""><br class=""></div><div class="">However clang-format will put these on separate lines:</div><div class=""><br class=""></div><div class=""><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">ierr = LibraryFunctionCall();</span></div><div class=""><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">CHKERRQ(ierr);</span></div><div class=""><br class=""></div><div class="">2. While this is somewhat more relaxed we don’t use spaces between parameters in function calls:</div><div class=""><br class=""></div><div class="">LibraryFunctionCall(arg1,arg2,arg3);</div><div class=""><br class=""></div><div class="">Which clang-format will change to:</div><div class=""><br class=""></div><div class=""><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">LibraryFunctionCall(arg1, arg2, arg3);</span></div><div class=""><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></span></div><div class=""><br class=""></div><div class="">Is there any way around either of these two? We’ve gone through the listed style-options  (<a href="https://clang.llvm.org/docs/ClangFormatStyleOptions.html" class="">https://clang.llvm.org/docs/ClangFormatStyleOptions.html</a>) but there doesn’t seem to be a publicly accessible option for the above. With this in mind, how feasible is it for clang to provide this? How feasible is it to implement these ourselves (perhaps as a clang-tidy-style plugin for clang-format or modifications to clang-format itself)?</div><div class=""><br class=""><div class="">
<div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div>Best regards,<br class=""><br class="">Jacob Faibussowitsch<br class="">(Jacob Fai - booss - oh - vitch)<br class=""></div></div></div>
</div>
<br class=""></div></body></html>