[PATCH] D24501: Remove redundant comma around parenthesis in parameter list.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 13 05:37:44 PDT 2016


ioeric created this revision.
ioeric added a reviewer: djasper.
ioeric added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

https://reviews.llvm.org/D24501

Files:
  lib/Format/Format.cpp
  unittests/Format/CleanupTest.cpp

Index: unittests/Format/CleanupTest.cpp
===================================================================
--- unittests/Format/CleanupTest.cpp
+++ unittests/Format/CleanupTest.cpp
@@ -142,15 +142,16 @@
   EXPECT_EQ(Expected, Result);
 }
 
-TEST_F(CleanupTest, ListSimpleRedundantComma) {
-  std::string Code = "void f() { std::vector<int> v = {1,2,,,3,{4,5}}; }";
-  std::string Expected = "void f() { std::vector<int> v = {1,2,3,{4,5}}; }";
+TEST_F(CleanupTest, ListRedundantComma) {
+  // Trailing comma in braces is not removed.
+  std::string Code = "void f() { std::vector<int> v = {1,2,,,3,{4,5,}}; }";
+  std::string Expected = "void f() { std::vector<int> v = {1,2,3,{4,5,}}; }";
   std::vector<tooling::Range> Ranges;
   Ranges.push_back(tooling::Range(40, 0));
   std::string Result = cleanup(Code, Ranges);
   EXPECT_EQ(Expected, Result);
 
-  Code = "int main() { f(1,,2,3,,4);}";
+  Code = "int main() { f(,1,,2,3,,4,);}";
   Expected = "int main() { f(1,2,3,4);}";
   Ranges.clear();
   Ranges.push_back(tooling::Range(17, 0));
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1019,6 +1019,8 @@
       if (Line->Affected) {
         cleanupRight(Line->First, tok::comma, tok::comma);
         cleanupRight(Line->First, TT_CtorInitializerColon, tok::comma);
+        cleanupRight(Line->First, tok::l_paren, tok::comma);
+        cleanupLeft(Line->First, tok::comma, tok::r_paren);
         cleanupLeft(Line->First, TT_CtorInitializerComma, tok::l_brace);
         cleanupLeft(Line->First, TT_CtorInitializerColon, tok::l_brace);
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24501.71149.patch
Type: text/x-patch
Size: 1657 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160913/1bb101df/attachment.bin>


More information about the cfe-commits mailing list