Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do the PointerAlignment options not work?

I'm using clang-format (version 8.0.0 (tags/google/stable/2019-01-18)) with a style file, in which I set

…
PointerAlignment: Left
…

This succeeds in transforming declarations such as this one

const string &foo = "lorem ipsum";

into

const string& foo = "lorem ipsum";

However, when I also include in my style file

BasedOnStyle: Google

the options do not do anything. For some reason, they get overridden by the base style. This seems nonsensical to me – the explicit options should override the base style instead, no? Can somebody explain what the problem is and how to use both BasedOnStyle and PointerAlignment: Left?

like image 779
oarfish Avatar asked Jun 06 '26 15:06

oarfish


1 Answers

The answer is that the Google style (one can inspect it with clang-format -style=google -dump-config | less) defines

DerivePointerAlignment: true

The documentation says it

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.

Which means one must explicitly set DerivePointerAlignment: false if one wants to handle it by oneself.

like image 157
oarfish Avatar answered Jun 10 '26 19:06

oarfish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!