[PATCH] D119785: [clang-format] Fix formatting of struct-like records followed by variable declaration.
Marek Kurdej via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 15 09:27:34 PST 2022
curdeius added inline comments.
================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:735
// We don't merge short records.
- FormatToken *RecordTok = Line.First;
- // Skip record modifiers.
- while (RecordTok->Next &&
- RecordTok->isOneOf(tok::kw_typedef, tok::kw_export,
- Keywords.kw_declare, Keywords.kw_abstract,
- tok::kw_default, Keywords.kw_override,
- tok::kw_public, tok::kw_private,
- tok::kw_protected, Keywords.kw_internal))
- RecordTok = RecordTok->Next;
- if (RecordTok &&
- RecordTok->isOneOf(tok::kw_class, tok::kw_union, tok::kw_struct,
- Keywords.kw_interface))
+ if (isRecordLBrace(*Line.Last))
return 0;
----------------
curdeius wrote:
> MyDeveloperDay wrote:
> > wow these are equivalent? do we need to worry about trailing comments?
> >
> > ```
> > public class A { /* comment */
> > ```
> Yes, before we were doing a poor man's scan skipping some (but not all) keywords (hence the bugs) that could appear before a record.
> That was error-prone and redundant w.r.t. the parsing done in UnwrappedLineParser.
>
> Anyway, good catch, I'll test what happens with comments.
@MyDeveloperDay, do we want this (probably more coherent):
```
verifyFormat("struct A {};", AllowSimpleBracedStatements); // already tested
verifyFormat("struct A { /* comment */ };", AllowSimpleBracedStatements); // added
```
or this (current behaviour):
```
verifyFormat("struct A {};", AllowSimpleBracedStatements); // already tested
verifyFormat("struct A { /* comment */\n"
"};", AllowSimpleBracedStatements); // added
```
(adapted from `TEST_F(FormatTest, FormatShortBracedStatements)`)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119785/new/
https://reviews.llvm.org/D119785
More information about the cfe-commits
mailing list