This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Don't annotate left brace of class as FunctionLBrace
ClosedPublic

Authored by owenpan on Mar 5 2023, 6:15 PM.

Details

Summary

The l_brace of class/struct/union was incorrectly annotated as TT_FunctionLBrace in the presence of attributes. This in turn would cause the RemoveSemicolon option to remove the semicolon at the end of the declaration, resulting in invalid code being generated.

Fixes https://github.com/llvm/llvm-project/issues/61188.

Diff Detail

Event Timeline

owenpan created this revision.Mar 5 2023, 6:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2023, 6:15 PM
owenpan requested review of this revision.Mar 5 2023, 6:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2023, 6:15 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
MyDeveloperDay accepted this revision.Mar 6 2023, 4:30 AM

Thanks for this, LGTM (maybe we can cherry pick this to 16.0)

This revision is now accepted and ready to land.Mar 6 2023, 4:30 AM

Thanks for this, LGTM (maybe we can cherry pick this to 16.0)

+1 because of the invalid code.

This revision was landed with ongoing or failed builds.Mar 6 2023, 1:07 PM
This revision was automatically updated to reflect the committed changes.

The upshot of this is better TT_FunctionLBrace/TT_ClassLBrace detection, which is great becuase if a class { or function { is incorrectly detected we are then in unknown territory as to how it might become formatted, since you introduced these Annotator tests, I fell we are really helping to lock down the other rules. I would hazard a guess that this actually solves more issues than we realize.

I would hazard a guess that this actually solves more issues than we realize.

That would be icing on the cake. :)