[PATCH] D25768: [Format] Cleanup after replacing constructor body with = default
Malcolm Parsons via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 20 08:08:19 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284732: [Format] Cleanup after replacing constructor body with = default (authored by malcolm.parsons).
Changed prior to commit:
https://reviews.llvm.org/D25768?vs=75138&id=75299#toc
Repository:
rL LLVM
https://reviews.llvm.org/D25768
Files:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/CleanupTest.cpp
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/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: cfe/trunk/lib/Format/Format.cpp
===================================================================
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/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);
}
}
Index: cfe/trunk/unittests/Format/CleanupTest.cpp
===================================================================
--- cfe/trunk/unittests/Format/CleanupTest.cpp
+++ cfe/trunk/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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25768.75299.patch
Type: text/x-patch
Size: 2654 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161020/698e8d54/attachment-0001.bin>
More information about the cfe-commits
mailing list