是的,AlignConsecutiveDeclarations 也会对齐函数参数。起初我并不确定,documentation 对此也不是很清楚,但是通过 clang-format 的source code 阅读,很明显函数参数对齐是设计使然:
void WhitespaceManager::alignConsecutiveDeclarations() {
...
AlignTokens(Style,
[](Change const &C) {
return C.Tok->is(TT_StartOfName) || // <-- variables
C.Tok->is(TT_FunctionDeclarationName) || // <-- parameters
C.Tok->is(tok::kw_operator);
},
...
您的示例中的精确对齐方式,我无法重现(尝试过 clang-format 5.0、6.0) - 对我来说,它将每个函数参数放在一行中:
ErrorType Layer::Construct(
AbstractManagedObject * a_parent,
container::Map<utf8::String, utf8::String> &a_configuration_attributess,
uint8_t a_opacity);
AlignConsecutiveDeclarations: true 可能与您的 clang 格式配置中的某些其他参数发生冲突,从而产生您所看到的结果。确保 BinPackParameters 设置为 false - 如果超出列限制,这应该强制将函数参数拆分为单独的行:
BinPackParameters(布尔型)
如果为 false,则函数声明或函数定义的参数要么都在同一行,要么各占一行。
如果您希望完全避免函数参数对齐,并愿意降级您的 clang-format 版本,您可以使用 clang-format 4.0。
AlignConsecutiveDeclarations 选项是在 3.8 版本中引入的,当时它没有对齐函数参数 - 只是连续的变量声明。将您的示例输入到 clang-format 3.8 会得到以下结果:
ErrorType Layer::Construct(
AbstractManagedObject *a_parent,
container::Map<utf8::String, utf8::String> &a_configuration_attributess,
uint8_t a_opacity);
在后续版本 3.9 和 4.0 中,AlignConsecutiveDeclarations 参数的功能保持不变。从 clang-format 5.0 开始,功能发生了变化,它也开始对齐函数参数。