This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Fix braced initializer formatting with templated base class initializer

Authored by galenelias on Jul 31 2023, 8:49 AM.



This fixes which
is a regression from where I
added logic to distinguish adjacent braces blocks between being braced
initializers or adjacent scopes by looking at the token before the first
opening brace to see if it is part of a class initializer list.

However, this logic fails to match initialization of a templated base
class initializer, because in that scenario the 'identifier' actually
ends in a >, so isn't detected. I am extending the logic to just also
detect > explicitly to be recognized as the braced initializer syntax.
Hopefully there aren't many more holes in the detection logic here.

Diff Detail

Event Timeline

galenelias created this revision.Jul 31 2023, 8:49 AM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptJul 31 2023, 8:49 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
galenelias requested review of this revision.Jul 31 2023, 8:49 AM

Please also add nested templates.

galenelias marked an inline comment as done.
galenelias added inline comments.

Ok, added A() : Base<Foo<int>>{} {} as a test case. I think that's what you mean by nested templates, but let me know if I misunderstood.

This revision is now accepted and ready to land.Aug 1 2023, 12:57 PM
owenpan accepted this revision.Aug 1 2023, 1:52 PM
This revision was automatically updated to reflect the committed changes.