llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.82k stars 11.46k forks source link

Allow modifiers (static, constexpr) on separate-ish line #37054

Open llvmbot opened 6 years ago

llvmbot commented 6 years ago
Bugzilla Link 37706
Version 6.0
OS Linux
Reporter LLVM Bugzilla Contributor

Extended Description

I'm having a number of issues trying to get clang-format to behave reasonably on https://github.com/Kitware/kwiver/blob/303a11ebb43c020ab8e48b6ef70407b460dba46b/vital/range/defs.h, using https://gist.github.com/mwoehlke-kitware/d8ef9466df5096a035059938aef2948d.

For this RFE, specifically, I have AlwaysBreakTemplateDeclarations enabled, which is good, but I also want the equivalent for non-type modifiers, e.g. inline, static and constexpr (and probably attributes). Ideally I would like these on the same line as template, but I would settle for template, attributes, and the rest of the above being on their own lines, provided that the keywords in the last category are kept on the same line. (In particular, see how clang-format butchers the end of KWIVER_RANGE_ADAPTER_TEMPLATE in the code mentioned above.)

So, specifically:

// best template static void foo()

// okay template static void foo()

// wrong static void foo()

llvmbot commented 6 years ago

I think it would suffice to have a new option to break between the return type, and anything preceding the return type which is not part of the return type. This would overlap with AlwaysBreakTemplateDeclarations, because turning it on would have the same effect if the template <...> is the only such thing, but it would also trigger breaks before attributes, inline, static and constexpr. (But it would have no effect on classes, so AlwaysBreakTemplateDeclarations would also still be relevant there.)

This also suggests how I could achieve exactly what I want; a new option as here described, and a 'classes only' value for AlwaysBreakTemplateDeclarations. (But again, I can live without that, especially as I probably only want template and inline on the same line in macro definitions as in the example file mentioned, if anywhere.)