This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Add option to align pointers in C style casts differently
AbandonedPublic

Authored by yodaldevoid on Dec 23 2021, 10:46 AM.

Details

Summary

I personally prefer that pointers are aligned to the right in most cases to avoid problems when multiple variables are declared at once. That said, I prefer left alignment in C style casts to avoid the extra space and because there is no chance of the sorts of problems you see in declarations. This setting supports people with preferences like mine.

Currently this affects the alignment of both pointers and references in C style casts. If someone wanted to affect references separately then a separate setting for that, similar to ReferenceAlignmet, could be added.

Diff Detail

Unit TestsFailed

Event Timeline

yodaldevoid requested review of this revision.Dec 23 2021, 10:46 AM
yodaldevoid created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 23 2021, 10:46 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Correct commit email

clang/lib/Format/TokenAnnotator.cpp
3045

What are Left and Right in your cases? I don't like the loop here and am not sure what exactly you want to check. Shouldn't Left be the PointerOrReference and Right is a r_paren?

clang/unittests/Format/FormatTest.cpp
15346

I think you should add some tests with simpler casts too.

Why this option is useful? Why would someone want to have a different alignment in casts than in other places?
As such I'm opposed to introducing one more option. Is there any well established code style that has something like this?

Why this option is useful? Why would someone want to have a different alignment in casts than in other places?
As such I'm opposed to introducing one more option. Is there any well established code style that has something like this?

Yes, we should adhere to the policy when adding new options.

yodaldevoid abandoned this revision.Dec 24 2021, 1:05 PM

Why this option is useful? Why would someone want to have a different alignment in casts than in other places?
As such I'm opposed to introducing one more option. Is there any well established code style that has something like this?

Yes, we should adhere to the policy when adding new options.

Understood. I'll close this out, then, as I don't know of a major project that needs this.