r284732 - [Format] Cleanup after replacing constructor body with = default
Malcolm Parsons via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 20 07:58:45 PDT 2016
Author: malcolm.parsons
Date: Thu Oct 20 09:58:45 2016
New Revision: 284732
URL: http://llvm.org/viewvc/llvm-project?rev=284732&view=rev
Log:
[Format] Cleanup after replacing constructor body with = default
Summary:
Remove colon and commas after replacing constructor body with = default.
Fix annotation of TT_CtorInitializerColon when preceded by a comment.
Reviewers: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D25768
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/CleanupTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=284732&r1=284731&r2=284732&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Oct 20 09:58:45 2016
@@ -1024,6 +1024,7 @@ public:
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);
}
}
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=284732&r1=284731&r2=284732&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Oct 20 09:58:45 2016
@@ -520,7 +520,8 @@ private:
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;
Modified: cfe/trunk/unittests/Format/CleanupTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/CleanupTest.cpp?rev=284732&r1=284731&r2=284732&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/CleanupTest.cpp (original)
+++ cfe/trunk/unittests/Format/CleanupTest.cpp Thu Oct 20 09:58:45 2016
@@ -151,6 +151,16 @@ TEST_F(CleanupTest, CtorInitializationSi
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 @@ TEST_F(CleanupTest, RemoveCommentsAround
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) {
More information about the cfe-commits
mailing list