为什么 PointerAlignment 选项不起作用?

Why do the PointerAlignment options not work?

我在样式文件中使用 clang-format (version 8.0.0 (tags/google/stable/2019-01-18)),我在其中设置了

…
PointerAlignment: Left
…

这成功地转换了这样的声明

const string &foo = "lorem ipsum";

进入

const string& foo = "lorem ipsum";

然而,当我也包含在我的样式文件中时

BasedOnStyle: Google

这些选项没有任何作用。由于某种原因,它们会被基本样式覆盖。这对我来说似乎很荒谬——显式选项应该覆盖基本样式,不是吗? 有人可以解释问题是什么以及如何同时使用 BasedOnStylePointerAlignment: Left 吗?

答案是 Google 样式(可以用 clang-format -style=google -dump-config | less 检查它)定义

DerivePointerAlignment: true

文档说了

If true, analyze the formatted file for the most common alignment of & and *. Pointer and reference alignment styles are going to be updated according to the preferences found in the file. PointerAlignment is then used only as fallback.

也就是说如果要自己处理就必须显式设置DerivePointerAlignment: false