Where are clang-format and clang-format.py in Mac OS X with Xcode Command Line Tools installed?

Seems like Apple doesn’t ship clang-format with the Command Line Tools. Right now you have at least three options: Using Homebrew (That’s the way to go) Using prebuild packages Build it yourself Homebrew As user johnhaley81 pointed out, clang-format is now in homebrew: clang-format is now on brew. brew install clang-format Please consider upvoting his … Read more

Can clang format add braces to single line if statements etc

clang-tidy can make syntactic changes to your code using FIXITS clang-tidy YOUR_FILE.cpp -fix -checks=”readability-braces-around-statements” — COMPILE_OPTIONS Updated: clang-tidy is a bit of a heavyweight tool for this as it needs compile options to parse the file, sadly clang-format (as of v3.9) won’t add braces. COMPILE_OPTIONS would be the include paths etc that you use to … Read more

Clang-format line breaks

So, having messed around in the clang format code and made some patches, here’s my two cents: Clang format is based on, parsing the AST using libclang, which basically eliminates all whitespace breaking up the token sequence into “unwrapped lines” which are like “logical” code lines Applying rules / configuration info to sometimes split up … Read more

clang-format: Setting to control C++ attributes

This is not a “solution”, but a general workaround for preventing clang-format (and other formatters) from removing line breaks. Just add an empty line comment at the end of a line like so: template <typename TChar> [[gnu::always_inline]] // static ptr<TChar> within_limit(ptr<TChar> first, ptr<TChar> last); template <typename TChar, typename FApply, typename… FApplyRest> [[gnu::always_inline]] // static ptr<TChar> … Read more