[PATCH] D30490: [change-namespace] get insertion points of forward declarations correct.
Eric Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 1 02:10:10 PST 2017
ioeric created this revision.
Previously, the insertion points would conflict with the old namespace
deletion.
https://reviews.llvm.org/D30490
Files:
change-namespace/ChangeNamespace.cpp
unittests/change-namespace/ChangeNamespaceTests.cpp
Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===================================================================
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -351,11 +351,13 @@
TEST_F(ChangeNamespaceTest, LeaveForwardDeclarationBehind) {
std::string Code = "namespace na {\n"
"namespace nb {\n"
+ "\n"
"class FWD;\n"
"class FWD2;\n"
"class A {\n"
" FWD *fwd;\n"
"};\n"
+ "\n"
"} // namespace nb\n"
"} // namespace na\n";
std::string Expected = "namespace na {\n"
@@ -370,6 +372,7 @@
"class A {\n"
" ::na::nb::FWD *fwd;\n"
"};\n"
+ "\n"
"} // namespace y\n"
"} // namespace x\n";
EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
Index: change-namespace/ChangeNamespace.cpp
===================================================================
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -697,8 +697,10 @@
const auto *NsDecl = Result.Nodes.getNodeAs<NamespaceDecl>("ns_decl");
// The namespace contains the forward declaration, so it must not be empty.
assert(!NsDecl->decls_empty());
- const auto Insertion = createInsertion(NsDecl->decls_begin()->getLocStart(),
- Code, *Result.SourceManager);
+ const auto Insertion =
+ createInsertion(getLocAfterNamespaceLBrace(NsDecl, *Result.SourceManager,
+ Result.Context->getLangOpts()),
+ Code, *Result.SourceManager);
InsertForwardDeclaration InsertFwd;
InsertFwd.InsertionOffset = Insertion.getOffset();
InsertFwd.ForwardDeclText = Insertion.getReplacementText().str();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30490.90131.patch
Type: text/x-patch
Size: 2065 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170301/4ba35626/attachment.bin>
More information about the cfe-commits
mailing list