clang-format: fix for 19986, extra spacing around c++14 lambda capture with initializer
Hello, Here's a little one-off patch that fixes https://llvm.org/bugs/show_bug.cgi?id=19986 for me, by allowing a few more things inside [] when trying to match a lambda capture section. I hope someone can help it find its way into the main repo. Cheers, Jacek Index: lib/Format/UnwrappedLineParser.cpp === --- lib/Format/UnwrappedLineParser.cpp (revision 263181) +++ lib/Format/UnwrappedLineParser.cpp (working copy) @@ -1080,8 +1080,25 @@ if (!FormatTok->isOneOf(tok::identifier, tok::kw_this)) return false; nextToken(); -if (FormatTok->is(tok::ellipsis)) +if (FormatTok->is(tok::equal)) { nextToken(); + int parens = 0; + while (!eof()) { +if (FormatTok->isOneOf(tok::l_paren, tok::l_square)) { + ++parens; +} else if (parens && FormatTok->isOneOf(tok::r_paren, tok::r_square)) { + --parens; +} else if (FormatTok->isOneOf(tok::comma, tok::r_square)) { + break; +} else if (!FormatTok->isOneOf(tok::identifier, tok::coloncolon)) { + return false; +} + +nextToken(); + } +} else if (FormatTok->is(tok::ellipsis)) { + nextToken(); +} if (FormatTok->is(tok::comma)) { nextToken(); } else if (FormatTok->is(tok::r_square)) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D18793: fix for 19986, extra spacing around c++14 lambda capture with initializer
arnetheduck created this revision. arnetheduck added a reviewer: djasper. arnetheduck added a subscriber: cfe-commits. Herald added a subscriber: klimek. Here's a little one-off patch that fixes https://llvm.org/bugs/show_bug.cgi?id=19986 for me, by allowing a few more things inside [] when trying to match a lambda capture section. I hope someone can help it find its way into the main repo. http://reviews.llvm.org/D18793 Files: lib/Format/UnwrappedLineParser.cpp Index: lib/Format/UnwrappedLineParser.cpp === --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -1080,8 +1080,25 @@ if (!FormatTok->isOneOf(tok::identifier, tok::kw_this)) return false; nextToken(); -if (FormatTok->is(tok::ellipsis)) +if (FormatTok->is(tok::equal)) { nextToken(); + int parens = 0; + while (!eof()) { +if (FormatTok->isOneOf(tok::l_paren, tok::l_square)) { + ++parens; +} else if (parens && FormatTok->isOneOf(tok::r_paren, tok::r_square)) { + --parens; +} else if (FormatTok->isOneOf(tok::comma, tok::r_square)) { + break; +} else if (!FormatTok->isOneOf(tok::identifier, tok::coloncolon)) { + return false; +} + +nextToken(); + } +} else if (FormatTok->is(tok::ellipsis)) { + nextToken(); +} if (FormatTok->is(tok::comma)) { nextToken(); } else if (FormatTok->is(tok::r_square)) { Index: lib/Format/UnwrappedLineParser.cpp === --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -1080,8 +1080,25 @@ if (!FormatTok->isOneOf(tok::identifier, tok::kw_this)) return false; nextToken(); -if (FormatTok->is(tok::ellipsis)) +if (FormatTok->is(tok::equal)) { nextToken(); + int parens = 0; + while (!eof()) { +if (FormatTok->isOneOf(tok::l_paren, tok::l_square)) { + ++parens; +} else if (parens && FormatTok->isOneOf(tok::r_paren, tok::r_square)) { + --parens; +} else if (FormatTok->isOneOf(tok::comma, tok::r_square)) { + break; +} else if (!FormatTok->isOneOf(tok::identifier, tok::coloncolon)) { + return false; +} + +nextToken(); + } +} else if (FormatTok->is(tok::ellipsis)) { + nextToken(); +} if (FormatTok->is(tok::comma)) { nextToken(); } else if (FormatTok->is(tok::r_square)) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D18793: fix for 19986, extra spacing around c++14 lambda capture with initializer
arnetheduck planned changes to this revision. arnetheduck added a comment. Thanks for the comments - I'll see when I have time to get back to this as the current patch happens to take care of my (rather limited) use case.. Comment at: lib/Format/UnwrappedLineParser.cpp:1086 @@ +1085,3 @@ + int parens = 0; + while (!eof()) { +if (FormatTok->isOneOf(tok::l_paren, tok::l_square)) { djasper wrote: > We need to be much more error resilient here as people will frequently call > clang-format with mismatched parentheses and such. I am actually quite > skeptical about having yet another instance of parentheses counting. Maybe > just call parseParens() instead? makes sense. Comment at: lib/Format/UnwrappedLineParser.cpp:1094 @@ +1093,3 @@ +} else if (!FormatTok->isOneOf(tok::identifier, tok::coloncolon)) { + return false; +} djasper wrote: > This seems wrong. Even in the case of the bug you say you are fixing, the > "23" is neither an identifier nor a coloncolon.. Ah, right... I've run it against our code base at work where it happened to be enough.. , but since full expressions can be used nowadays, I guess it's a lot more than just these to that *can* appear. http://reviews.llvm.org/D18793 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits