[PATCH] D156705: [clang-format] Fix braced initializer formatting with templated base class initializer
This revision was automatically updated to reflect the committed changes. Closed by commit rG400da115c58a: [clang-format] Fix braced initializer with templated base class (authored by galenelias, committed by owenpan). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D156705/new/ https://reviews.llvm.org/D156705 Files: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -13458,6 +13458,8 @@ verifyFormat( "class A {\n" " A() : a{} {}\n" + " A() : Base{} {}\n" + " A() : Base>{} {}\n" " A(int b) : b(b) {}\n" " A(int a, int b) : a(a), bs{{bs...}} { f(); }\n" " int a, b;\n" Index: clang/lib/Format/UnwrappedLineParser.cpp === --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -581,7 +581,8 @@ ProbablyBracedList = ProbablyBracedList || (NextTok->is(tok::l_brace) && LBraceStack.back().PrevTok && - LBraceStack.back().PrevTok->is(tok::identifier)); + LBraceStack.back().PrevTok->isOneOf(tok::identifier, + tok::greater)); ProbablyBracedList = ProbablyBracedList || Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -13458,6 +13458,8 @@ verifyFormat( "class A {\n" " A() : a{} {}\n" + " A() : Base{} {}\n" + " A() : Base>{} {}\n" " A(int b) : b(b) {}\n" " A(int a, int b) : a(a), bs{{bs...}} { f(); }\n" " int a, b;\n" Index: clang/lib/Format/UnwrappedLineParser.cpp === --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -581,7 +581,8 @@ ProbablyBracedList = ProbablyBracedList || (NextTok->is(tok::l_brace) && LBraceStack.back().PrevTok && - LBraceStack.back().PrevTok->is(tok::identifier)); + LBraceStack.back().PrevTok->isOneOf(tok::identifier, + tok::greater)); ProbablyBracedList = ProbablyBracedList || ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D156705: [clang-format] Fix braced initializer formatting with templated base class initializer
galenelias added inline comments. Comment at: clang/unittests/Format/FormatTest.cpp:13461 " A() : a{} {}\n" + " A() : Base{} {}\n" " A(int b) : b(b) {}\n" HazardyKnusperkeks wrote: > Please also add nested templates. Ok, added `A() : Base>{} {}` as a test case. I think that's what you mean by nested templates, but let me know if I misunderstood. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D156705/new/ https://reviews.llvm.org/D156705 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D156705: [clang-format] Fix braced initializer formatting with templated base class initializer
galenelias updated this revision to Diff 545798. galenelias marked an inline comment as done. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D156705/new/ https://reviews.llvm.org/D156705 Files: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -13458,6 +13458,8 @@ verifyFormat( "class A {\n" " A() : a{} {}\n" + " A() : Base{} {}\n" + " A() : Base>{} {}\n" " A(int b) : b(b) {}\n" " A(int a, int b) : a(a), bs{{bs...}} { f(); }\n" " int a, b;\n" Index: clang/lib/Format/UnwrappedLineParser.cpp === --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -581,7 +581,8 @@ ProbablyBracedList = ProbablyBracedList || (NextTok->is(tok::l_brace) && LBraceStack.back().PrevTok && - LBraceStack.back().PrevTok->is(tok::identifier)); + LBraceStack.back().PrevTok->isOneOf(tok::identifier, + tok::greater)); ProbablyBracedList = ProbablyBracedList || Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -13458,6 +13458,8 @@ verifyFormat( "class A {\n" " A() : a{} {}\n" + " A() : Base{} {}\n" + " A() : Base>{} {}\n" " A(int b) : b(b) {}\n" " A(int a, int b) : a(a), bs{{bs...}} { f(); }\n" " int a, b;\n" Index: clang/lib/Format/UnwrappedLineParser.cpp === --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -581,7 +581,8 @@ ProbablyBracedList = ProbablyBracedList || (NextTok->is(tok::l_brace) && LBraceStack.back().PrevTok && - LBraceStack.back().PrevTok->is(tok::identifier)); + LBraceStack.back().PrevTok->isOneOf(tok::identifier, + tok::greater)); ProbablyBracedList = ProbablyBracedList || ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D156705: [clang-format] Fix braced initializer formatting with templated base class initializer
HazardyKnusperkeks added inline comments. Comment at: clang/unittests/Format/FormatTest.cpp:13461 " A() : a{} {}\n" + " A() : Base{} {}\n" " A(int b) : b(b) {}\n" Please also add nested templates. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D156705/new/ https://reviews.llvm.org/D156705 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D156705: [clang-format] Fix braced initializer formatting with templated base class initializer
galenelias created this revision. Herald added projects: All, clang, clang-format. Herald added a subscriber: cfe-commits. Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay. galenelias requested review of this revision. 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. https://reviews.llvm.org/D156705 Files: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -13458,6 +13458,7 @@ verifyFormat( "class A {\n" " A() : a{} {}\n" + " A() : Base{} {}\n" " A(int b) : b(b) {}\n" " A(int a, int b) : a(a), bs{{bs...}} { f(); }\n" " int a, b;\n" Index: clang/lib/Format/UnwrappedLineParser.cpp === --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -581,7 +581,8 @@ ProbablyBracedList = ProbablyBracedList || (NextTok->is(tok::l_brace) && LBraceStack.back().PrevTok && - LBraceStack.back().PrevTok->is(tok::identifier)); + LBraceStack.back().PrevTok->isOneOf(tok::identifier, + tok::greater)); ProbablyBracedList = ProbablyBracedList || Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -13458,6 +13458,7 @@ verifyFormat( "class A {\n" " A() : a{} {}\n" + " A() : Base{} {}\n" " A(int b) : b(b) {}\n" " A(int a, int b) : a(a), bs{{bs...}} { f(); }\n" " int a, b;\n" Index: clang/lib/Format/UnwrappedLineParser.cpp === --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -581,7 +581,8 @@ ProbablyBracedList = ProbablyBracedList || (NextTok->is(tok::l_brace) && LBraceStack.back().PrevTok && - LBraceStack.back().PrevTok->is(tok::identifier)); + LBraceStack.back().PrevTok->isOneOf(tok::identifier, + tok::greater)); ProbablyBracedList = ProbablyBracedList || ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits