MyDeveloperDay created this revision. MyDeveloperDay added reviewers: HazardyKnusperkeks, curdeius, JohelEGP. MyDeveloperDay added projects: clang, clang-format. MyDeveloperDay requested review of this revision.
https://github.com/llvm/llvm-project/issues/46505 The presence of a lambda in an argument template list ignored the [] as a lambda at all, this caused the contents of the <> to be incorrectly analyzed. struct Y : X < [] { return 0; } > {}; Fixes: #46505 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D116806 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 @@ -23161,6 +23161,16 @@ Style); } +TEST_F(FormatTest, ShortTemplatedArgumentLists) { + auto Style = getLLVMStyle(); + + verifyFormat("struct Y : X<[] { return 0; }> {};", Style); + verifyFormat("struct Y<[] { return 0; }> {};", Style); + + verifyFormat("struct Z : X<decltype([] { return 0; }){}> {};", Style); + verifyFormat("template <auto> struct X {};", Style); +} + } // namespace } // namespace format } // namespace clang Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2869,6 +2869,9 @@ if (!tryToParseBracedList()) break; } + if (FormatTok->is(tok::l_square)) + if (!tryToParseLambda()) + break; if (FormatTok->Tok.is(tok::semi)) return; if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -23161,6 +23161,16 @@ Style); } +TEST_F(FormatTest, ShortTemplatedArgumentLists) { + auto Style = getLLVMStyle(); + + verifyFormat("struct Y : X<[] { return 0; }> {};", Style); + verifyFormat("struct Y<[] { return 0; }> {};", Style); + + verifyFormat("struct Z : X<decltype([] { return 0; }){}> {};", Style); + verifyFormat("template <auto> struct X {};", Style); +} + } // namespace } // namespace format } // namespace clang Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2869,6 +2869,9 @@ if (!tryToParseBracedList()) break; } + if (FormatTok->is(tok::l_square)) + if (!tryToParseLambda()) + break; if (FormatTok->Tok.is(tok::semi)) return; if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits