r190046 - clang-format: Quickfix for braced init lists detected as lambdas.
Daniel Jasper
djasper at google.com
Thu Sep 5 04:49:39 PDT 2013
Author: djasper
Date: Thu Sep 5 06:49:39 2013
New Revision: 190046
URL: http://llvm.org/viewvc/llvm-project?rev=190046&view=rev
Log:
clang-format: Quickfix for braced init lists detected as lambdas.
Before:
constexpr char hello [] { "hello" };
After:
constexpr char hello[]{ "hello" };
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=190046&r1=190045&r2=190046&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Thu Sep 5 06:49:39 2013
@@ -674,6 +674,12 @@ void UnwrappedLineParser::parseStructura
}
void UnwrappedLineParser::tryToParseLambda() {
+ // FIXME: This is a dirty way to access the previous token. Find a better
+ // solution.
+ if (!Line->Tokens.empty() && Line->Tokens.back().Tok->is(tok::identifier)) {
+ nextToken();
+ return;
+ }
assert(FormatTok->is(tok::l_square));
FormatToken &LSquare = *FormatTok;
if (!tryToParseLambdaIntroducer())
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=190046&r1=190045&r2=190046&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Sep 5 06:49:39 2013
@@ -6300,6 +6300,9 @@ TEST_F(FormatTest, FormatsLambdas) {
" x.end(), //\n"
" [&](int, int) { return 1; });\n"
"}\n");
+
+ // Not lambdas.
+ verifyFormat("constexpr char hello[]{ \"hello\" };");
}
TEST_F(FormatTest, FormatsBlocks) {
More information about the cfe-commits
mailing list