[PATCH] D25768: [Format] Cleanup after replacing constructor body with = default
Malcolm Parsons via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 19 06:38:37 PDT 2016
malcolm.parsons created this revision.
malcolm.parsons added a reviewer: djasper.
malcolm.parsons added a subscriber: cfe-commits.
Herald added a subscriber: klimek.
Remove colon and commas after replacing constructor body with = default.
Fix annotation of TT_CtorInitializerColon when preceded by a comment.
https://reviews.llvm.org/D25768
Files:
lib/Format/Format.cpp
lib/Format/TokenAnnotator.cpp
unittests/Format/CleanupTest.cpp
Index: unittests/Format/CleanupTest.cpp
===================================================================
--- unittests/Format/CleanupTest.cpp
+++ unittests/Format/CleanupTest.cpp
@@ -151,6 +151,16 @@
EXPECT_EQ(Expected, cleanupAroundOffsets({15}, Code));
}
+TEST_F(CleanupTest, CtorInitializationSimpleRedundantColon) {
+ std::string Code = "class A {\nA() : =default; };";
+ std::string Expected = "class A {\nA() =default; };";
+ EXPECT_EQ(Expected, cleanupAroundOffsets({15}, Code));
+
+ Code = "class A {\nA() : , =default; };";
+ Expected = "class A {\nA() =default; };";
+ EXPECT_EQ(Expected, cleanupAroundOffsets({15}, Code));
+}
+
TEST_F(CleanupTest, ListRedundantComma) {
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}}; }";
@@ -239,6 +249,14 @@
Code = "class A {\nA() : , // comment\n y(1),{} };";
Expected = "class A {\nA() : // comment\n y(1){} };";
EXPECT_EQ(Expected, cleanupAroundOffsets({17}, Code));
+
+ Code = "class A {\nA() // comment\n : ,,{} };";
+ Expected = "class A {\nA() // comment\n {} };";
+ EXPECT_EQ(Expected, cleanupAroundOffsets({30}, Code));
+
+ Code = "class A {\nA() // comment\n : ,,=default; };";
+ Expected = "class A {\nA() // comment\n =default; };";
+ EXPECT_EQ(Expected, cleanupAroundOffsets({30}, Code));
}
TEST_F(CleanupTest, CtorInitializerInNamespace) {
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -520,7 +520,8 @@
Tok->Type = TT_BitFieldColon;
} else if (Contexts.size() == 1 &&
!Line.First->isOneOf(tok::kw_enum, tok::kw_case)) {
- if (Tok->Previous->isOneOf(tok::r_paren, tok::kw_noexcept))
+ if (Tok->getPreviousNonComment()->isOneOf(tok::r_paren,
+ tok::kw_noexcept))
Tok->Type = TT_CtorInitializerColon;
else
Tok->Type = TT_InheritanceColon;
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1024,6 +1024,7 @@
cleanupLeft(Line->First, tok::comma, tok::r_paren);
cleanupLeft(Line->First, TT_CtorInitializerComma, tok::l_brace);
cleanupLeft(Line->First, TT_CtorInitializerColon, tok::l_brace);
+ cleanupLeft(Line->First, TT_CtorInitializerColon, tok::equal);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25768.75138.patch
Type: text/x-patch
Size: 2564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161019/7560f8d9/attachment.bin>
More information about the cfe-commits
mailing list