This is an archive of the discontinued LLVM Phabricator instance.

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

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

Details

Summary

This fixes https://github.com/llvm/llvm-project/issues/64134 which
is a regression from https://reviews.llvm.org/D150403 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
clang/unittests/Format/FormatTest.cpp
13461

Please also add nested templates.

galenelias marked an inline comment as done.
galenelias added inline comments.
clang/unittests/Format/FormatTest.cpp
13461

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.