Index: lib/Tooling/Core/QualTypeNames.cpp =================================================================== --- lib/Tooling/Core/QualTypeNames.cpp +++ lib/Tooling/Core/QualTypeNames.cpp @@ -383,7 +383,10 @@ } NestedNameSpecifier *Prefix = nullptr; - Qualifiers PrefixQualifiers; + // Local qualifiers are attached to the Qualtype outside of the + // elaborated type. Retrieve them before descending into the + // elaborated type. + Qualifiers PrefixQualifiers = QT.getLocalQualifiers(); ElaboratedTypeKeyword Keyword = ETK_None; if (const auto *ETypeInput = dyn_cast(QT.getTypePtr())) { QT = ETypeInput->getNamedType(); @@ -395,8 +398,7 @@ true /*FullyQualified*/); // move the qualifiers on the outer type (avoid 'std::const string'!) - if (Prefix) { - PrefixQualifiers = QT.getLocalQualifiers(); + if (Prefix || Keyword != ETK_None) { QT = QualType(QT.getTypePtr(), 0); } Index: unittests/Tooling/QualTypeNamesTest.cpp =================================================================== --- unittests/Tooling/QualTypeNamesTest.cpp +++ unittests/Tooling/QualTypeNamesTest.cpp @@ -88,6 +88,7 @@ "Foo::non_dependent_type"; Visitor.ExpectedQualTypeNames["AnEnumVar"] = "EnumScopeClass::AnEnum"; Visitor.ExpectedQualTypeNames["AliasTypeVal"] = "A::B::C::InnerAlias"; + Visitor.ExpectedQualTypeNames["CheckM"] = "const A::B::Class0 *"; Visitor.runOver( "int CheckInt;\n" "template \n" @@ -108,6 +109,7 @@ " AnotherClass> CheckC);\n" " void Function2(Template0,\n" " Template0 > CheckD);\n" + " void Function3(const B::Class0* CheckM);\n" " }\n" "template class Variadic {};\n" "Variadic, "