Index: change-namespace/ChangeNamespace.cpp =================================================================== --- change-namespace/ChangeNamespace.cpp +++ change-namespace/ChangeNamespace.cpp @@ -697,8 +697,10 @@ const auto *NsDecl = Result.Nodes.getNodeAs("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(); 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));