forked from OSchip/llvm-project
[clang-format] Make checking for a record more robust and avoid a loop.
This commit is contained in:
parent
8ad39fbaf2
commit
ef39235cb9
|
@ -312,10 +312,15 @@ private:
|
|||
break;
|
||||
|
||||
// Check if the found line starts a record.
|
||||
for (const FormatToken *RecordTok = (*J)->Last; RecordTok;
|
||||
RecordTok = RecordTok->Previous)
|
||||
if (RecordTok->is(tok::l_brace))
|
||||
return isRecordLBrace(*RecordTok);
|
||||
const FormatToken *LastNonComment = (*J)->Last;
|
||||
assert(LastNonComment);
|
||||
if (LastNonComment->is(tok::comment)) {
|
||||
LastNonComment = LastNonComment->getPreviousNonComment();
|
||||
// There must be another token (usually `{`), because we chose a
|
||||
// line that has a smaller level.
|
||||
assert(LastNonComment);
|
||||
}
|
||||
return isRecordLBrace(*LastNonComment);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3809,6 +3809,18 @@ TEST_F(FormatTest, FormatsNamespaces) {
|
|||
" }\n"
|
||||
"} // namespace\n",
|
||||
ShortInlineFunctions);
|
||||
verifyFormat("namespace { /* comment */\n"
|
||||
" void f() {\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
"} // namespace\n",
|
||||
ShortInlineFunctions);
|
||||
verifyFormat("namespace { // comment\n"
|
||||
" void f() {\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
"} // namespace\n",
|
||||
ShortInlineFunctions);
|
||||
verifyFormat("namespace {\n"
|
||||
" int some_int;\n"
|
||||
" void f() {\n"
|
||||
|
@ -3828,6 +3840,18 @@ TEST_F(FormatTest, FormatsNamespaces) {
|
|||
" };\n"
|
||||
"} // namespace\n",
|
||||
ShortInlineFunctions);
|
||||
verifyFormat("namespace {\n"
|
||||
" class X { /* comment */\n"
|
||||
" void f() { return; }\n"
|
||||
" };\n"
|
||||
"} // namespace\n",
|
||||
ShortInlineFunctions);
|
||||
verifyFormat("namespace {\n"
|
||||
" class X { // comment\n"
|
||||
" void f() { return; }\n"
|
||||
" };\n"
|
||||
"} // namespace\n",
|
||||
ShortInlineFunctions);
|
||||
verifyFormat("namespace {\n"
|
||||
" struct X {\n"
|
||||
" void f() { return; }\n"
|
||||
|
|
Loading…
Reference in New Issue