This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Fix a bug that misformats Access Specifier after *[]
ClosedPublic

Authored by owenpan on Apr 27 2022, 6:12 PM.

Diff Detail

Event Timeline

owenpan created this revision.Apr 27 2022, 6:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 6:12 PM
owenpan requested review of this revision.Apr 27 2022, 6:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 6:12 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Looks more or less correct, but I am afraid that this change may misbehave in some rare cases.
Consider *[](auto *x) { return x; }();, so an immediately invoked lambda returning a pointer.
It seems to be correctly formatted currently, but I don't see any test on it.
Could you add a test for this please?

owenpan updated this revision to Diff 425710.Apr 28 2022, 1:16 AM

Also checks the token before * and adds a test case.

Looks more or less correct, but I am afraid that this change may misbehave in some rare cases.
Consider *[](auto *x) { return x; }();, so an immediately invoked lambda returning a pointer.
It seems to be correctly formatted currently, but I don't see any test on it.
Could you add a test for this please?

Good catch!

curdeius added inline comments.Apr 28 2022, 2:24 AM
clang/unittests/Format/FormatTest.cpp
3342

How about int const *, const int*? Is const & co. a simple type specifier?

I currently don't know exactly how isSimpleTypeSpecifier works, but what is with
auto x = Foo * []{return 5;}();
auto x = Foo * *[]{static y = 5; return &y;}();

This revision is now accepted and ready to land.Apr 28 2022, 2:25 AM
owenpan updated this revision to Diff 426307.May 1 2022, 1:03 PM

Instead of looking back, look ahead in tryToParseLambdaIntroducer().

Now that we look ahead instead of looking back, it doesn't matter what comes before *[] or [].

clang/unittests/Format/FormatTest.cpp
3342

It doesn't matter what comes before *[] now that we look ahead for a >.

curdeius accepted this revision.May 2 2022, 1:26 AM