This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Handle object instansiation in if-statements
ClosedPublic

Authored by thieta on Nov 3 2022, 4:23 AM.

Details

Summary

Before this patch code like this:

if (Class* obj{getObject()}) { }

would be mis-formated since the * would be annotated as a
binaryoperator.

This patch changes the * to become a PointerOrReference instead
and fixes the formatting issues.

Diff Detail

Event Timeline

thieta created this revision.Nov 3 2022, 4:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2022, 4:23 AM
thieta requested review of this revision.Nov 3 2022, 4:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2022, 4:23 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rymiel added a project: Restricted Project.Nov 3 2022, 6:23 AM
HazardyKnusperkeks added inline comments.
clang/lib/Format/TokenAnnotator.cpp
366

Could you add a test for this as well?

clang/unittests/Format/TokenAnnotatorTest.cpp
1050

There is already a test case for star amp understanding, please use that.

thieta updated this revision to Diff 473169.Nov 4 2022, 2:11 AM

Expand and move testing

thieta marked 2 inline comments as done.Nov 4 2022, 2:12 AM

I have expanded testing and moved it to the place you suggested.

This revision is now accepted and ready to land.Nov 6 2022, 10:45 AM
This revision was landed with ongoing or failed builds.Nov 6 2022, 11:35 PM
This revision was automatically updated to reflect the committed changes.

because of https://github.com/llvm/llvm-project/issues/61785 should this really be reverted? is basically saying X * Y { must be X *Y{ but that obviously not the case

because of https://github.com/llvm/llvm-project/issues/61785 should this really be reverted? is basically saying X * Y { must be X *Y{ but that obviously not the case

Tricky one. Any ideas on how we could differentiate those two cases? Maybe impossible? Not sure what the normal way to handle ambiguous things like that in clang-format is.

because of https://github.com/llvm/llvm-project/issues/61785 should this really be reverted? is basically saying X * Y { must be X *Y{ but that obviously not the case

Tricky one. Any ideas on how we could differentiate those two cases? Maybe impossible? Not sure what the normal way to handle ambiguous things like that in clang-format is.

I would prefer we avoid the regression that this issue caused, even if both are equally viable. because otherwise we get blamed for "changing defaults" @owenpan, @HazardyKnusperkeks what are your thoughts?

because of https://github.com/llvm/llvm-project/issues/61785 should this really be reverted? is basically saying X * Y { must be X *Y{ but that obviously not the case

Tricky one. Any ideas on how we could differentiate those two cases? Maybe impossible? Not sure what the normal way to handle ambiguous things like that in clang-format is.

I would prefer we avoid the regression that this issue caused, even if both are equally viable. because otherwise we get blamed for "changing defaults" @owenpan, @HazardyKnusperkeks what are your thoughts?

I have no idea when the release was/is. If it is not released it's a no brainer, revert. Otherwise I'm torn... for everyone skipping this release a revert would change nothing, for those who keep up to date we could be ping-ponging.

Can we solve the problem, without knowing what identifiers are types and what are objects/variables for all valid and not pathologic cases?

This was released in LLVM 16.0.0.

This was released in LLVM 16.0.0.

I think we should revert it in 16.0.1.

because of https://github.com/llvm/llvm-project/issues/61785 should this really be reverted? is basically saying X * Y { must be X *Y{ but that obviously not the case

Tricky one. Any ideas on how we could differentiate those two cases? Maybe impossible? Not sure what the normal way to handle ambiguous things like that in clang-format is.

We can add a Types option similar to StatementMacros.

I like both @owenpan suggestions

This was released in LLVM 16.0.0.

The prior behaviour was there before, it’s marked in GitHub as a regression, can you please revert, we’ll mark the issue to be cherry picked, then let’s go back and rework a solution that means your issue can be resolved

This was released in LLVM 16.0.0.

The prior behaviour was there before, it’s marked in GitHub as a regression, can you please revert, we’ll mark the issue to be cherry picked, then let’s go back and rework a solution that means your issue can be resolved

Sorry this slipped under my radar. Can you please push a revert to main and then file a issue to backport this to the release branch if it's something you still want to do. It's hard for me to keep track of the issues unless they are added to the 16.x milestone.

This was released in LLVM 16.0.0.

The prior behaviour was there before, it’s marked in GitHub as a regression, can you please revert, we’ll mark the issue to be cherry picked, then let’s go back and rework a solution that means your issue can be resolved

Sorry this slipped under my radar. Can you please push a revert to main and then file a issue to backport this to the release branch if it's something you still want to do. It's hard for me to keep track of the issues unless they are added to the 16.x milestone.

You have commit rights correct? you really need to own your change especially if it causes a regression.

You have commit rights correct? you really need to own your change especially if it causes a regression.

Alright - I did that now. Sorry I am just used to be on the other side as my role as a release manager and I thought you where asking me to revert it in that role.

I will see if I find time to add the new Types directive soon.