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);
       }


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);
       }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to