From: Benjamin Kramer Date: Fri, 15 Mar 2019 11:09:41 +0000 (+0000) Subject: Make getFullyQualifiedName qualify both the pointee and class type for member ptr... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96fadfc081a928c036cd457470f976c9de4ae736;p=clang Make getFullyQualifiedName qualify both the pointee and class type for member ptr types We already handle pointers and references, member ptrs are just another special case. Fixes PR40732. Differential Revision: https://reviews.llvm.org/D59387 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356250 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/QualTypeNames.cpp b/lib/AST/QualTypeNames.cpp index ce01f66297..f28f00171c 100644 --- a/lib/AST/QualTypeNames.cpp +++ b/lib/AST/QualTypeNames.cpp @@ -379,6 +379,19 @@ QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx, return QT; } + if (auto *MPT = dyn_cast(QT.getTypePtr())) { + // Get the qualifiers. + Qualifiers Quals = QT.getQualifiers(); + // Fully qualify the pointee and class types. + QT = getFullyQualifiedType(QT->getPointeeType(), Ctx, WithGlobalNsPrefix); + QualType Class = getFullyQualifiedType(QualType(MPT->getClass(), 0), Ctx, + WithGlobalNsPrefix); + QT = Ctx.getMemberPointerType(QT, Class.getTypePtr()); + // Add back the qualifiers. + QT = Ctx.getQualifiedType(QT, Quals); + return QT; + } + // In case of myType& we need to strip the reference first, fully // qualify and attach the reference once again. if (isa(QT.getTypePtr())) { diff --git a/unittests/Tooling/QualTypeNamesTest.cpp b/unittests/Tooling/QualTypeNamesTest.cpp index 0b85beb106..b6c3029778 100644 --- a/unittests/Tooling/QualTypeNamesTest.cpp +++ b/unittests/Tooling/QualTypeNamesTest.cpp @@ -194,6 +194,7 @@ TEST(QualTypeNameTest, getFullyQualifiedName) { GlobalNsPrefix.ExpectedQualTypeNames["ZVal"] = "::A::B::Y::Z"; GlobalNsPrefix.ExpectedQualTypeNames["GlobalZVal"] = "::Z"; GlobalNsPrefix.ExpectedQualTypeNames["CheckK"] = "D::aStruct"; + GlobalNsPrefix.ExpectedQualTypeNames["YZMPtr"] = "::A::B::X ::A::B::Y::Z::*"; GlobalNsPrefix.runOver( "namespace A {\n" " namespace B {\n" @@ -205,8 +206,9 @@ TEST(QualTypeNameTest, getFullyQualifiedName) { " template \n" " using Alias = CCC;\n" " Alias IntAliasVal;\n" - " struct Y { struct Z {}; };\n" + " struct Y { struct Z { X YZIPtr; }; };\n" " Y::Z ZVal;\n" + " X Y::Z::*YZMPtr;\n" " }\n" "}\n" "struct Z {};\n"