Patch for clang-format to allow references and pointers to bind differently

Ben Longbons brlongbons at gmail.com
Wed Nov 27 17:50:34 PST 2013


On Wed, Nov 27, 2013 at 2:26 PM, Daniel Jasper <djasper at google.com> wrote:
> This does not make any sense to me and I'd vote against putting it into
> clang-format. Can you explain the rationale behind this formatting decision?
It's certainly not the most *popular* formatting style, but it's the
one I learned. Some other formatting tools, such as astyle, support
this style.
I'm guessing the reason I learned this style was because my background
was C before C++, and most C code uses "int *var" but a lot of C++
code uses "int& var" and avoids pointers.
Note that the ambiguity doesn't usually happen in practice with
references because references must be initialized so only one is
declared on each line.

I'm trying to go from manually-enforced style to automatically, and I
don't want the first formatting run to introduce a huge diff. I think
that is the *single* *biggest* *thing* people want out of a formatting
tool. It's not your job try to force one particular style on anyone
(unless you're writing a new language - Go did this well).

There are other things I need that clang-format doesn't support yet
(such as forcing a newline after constexpr/static/inline and indenting
preprocessor directives), but this patch was the easiest to make.

-o11c



More information about the cfe-commits mailing list