r190207 - clang-format: Don't confuse operator[] with lambdas.

Daniel Jasper djasper at google.com
Fri Sep 6 14:25:51 PDT 2013


Author: djasper
Date: Fri Sep  6 16:25:51 2013
New Revision: 190207

URL: http://llvm.org/viewvc/llvm-project?rev=190207&view=rev
Log:
clang-format: Don't confuse operator[] with lambdas.

Before:
  double &operator[](int i) { return 0; } int i;

After:
  double &operator[](int i) { return 0; }
  int i;

This fixes llvm.org/PR17134.

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=190207&r1=190206&r2=190207&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Sep  6 16:25:51 2013
@@ -676,7 +676,8 @@ 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)) {
+  if (!Line->Tokens.empty() &&
+      Line->Tokens.back().Tok->isOneOf(tok::identifier, tok::kw_operator)) {
     nextToken();
     return;
   }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=190207&r1=190206&r2=190207&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Sep  6 16:25:51 2013
@@ -6399,6 +6399,8 @@ TEST_F(FormatTest, FormatsLambdas) {
 
   // Not lambdas.
   verifyFormat("constexpr char hello[]{ \"hello\" };");
+  verifyFormat("double &operator[](int i) { return 0; }\n"
+               "int i;");
 }
 
 TEST_F(FormatTest, FormatsBlocks) {





More information about the cfe-commits mailing list