Index: change-namespace/ChangeNamespace.cpp =================================================================== --- change-namespace/ChangeNamespace.cpp +++ change-namespace/ChangeNamespace.cpp @@ -552,6 +552,10 @@ if (Loc.getTypeLocClass() == TypeLoc::Elaborated) { NestedNameSpecifierLoc NestedNameSpecifier = Loc.castAs().getQualifierLoc(); + // This happens for friend declaration of a base class with injected class + // name. + if (!NestedNameSpecifier.getNestedNameSpecifier()) + return; const Type *SpecifierType = NestedNameSpecifier.getNestedNameSpecifier()->getAsType(); if (SpecifierType && SpecifierType->isRecordType()) Index: unittests/change-namespace/ChangeNamespaceTests.cpp =================================================================== --- unittests/change-namespace/ChangeNamespaceTests.cpp +++ unittests/change-namespace/ChangeNamespaceTests.cpp @@ -2154,6 +2154,60 @@ EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code)); } +TEST_F(ChangeNamespaceTest, InjectedClassNameInFriendDecl) { + OldNamespace = "d"; + NewNamespace = "e"; + std::string Code = "namespace a{\n" + "template \n" + "class Base {\n" + " public:\n" + " void f() {\n" + " T t;\n" + " t.priv();\n" + " }\n" + "};\n" + "} // namespace a\n" + "namespace d {\n" + "class D : public a::Base {\n" + " private:\n" + " friend class Base;\n" + " void priv() {}\n" + " Base b;\n" + "};\n" + "\n" + "void f() {\n" + " D d;\n" + " a:: Base b;\n" + " b.f();\n" + "}\n" + "} // namespace d\n"; + std::string Expected = "namespace a{\n" + "template \n" + "class Base {\n" + " public:\n" + " void f() {\n" + " T t;\n" + " t.priv();\n" + " }\n" + "};\n" + "} // namespace a\n" + "\n" + "namespace e {\n" + "class D : public a::Base {\n" + " private:\n" + " friend class Base;\n" + " void priv() {}\n" + " a::Base b;\n" + "};\n" + "\n" + "void f() {\n" + " D d;\n" + " a::Base b;\n" + " b.f();\n" + "}\n" + "} // namespace e\n"; + EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code)); +} } // anonymous namespace } // namespace change_namespace