Skip to content

Being explicit about pointer placement in formatting

I've just had a fun hour trying to find out why all my pointers were shifting to the left...

i.e.

struct cell* ci

not

struct cell *ci 

It turns out running:

clang-format -style=file -dump-config | grep -Ei 'DerivePointerAlignment|PointerAlignment'

on master yields:

DerivePointerAlignment: true
PointerAlignment: Left

Which is all well and good because DerivePointerAlignment takes precedence. However, should you (for argument's sake) screw up your local formatter config and accidentally shift pointers to the left, then there is no saving yourself because both options point to the left now.

While this scenario is unlikely to happen to anyone else, we should probably actually define explicitly what we want for this in the format config and not rely on matching what is present in the file.

Edited by William Roper

Merge request reports

Loading