]> granicus.if.org Git - clang/commitdiff
Make getFullyQualifiedName qualify both the pointee and class type for member ptr...
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 15 Mar 2019 11:09:41 +0000 (11:09 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 15 Mar 2019 11:09:41 +0000 (11:09 +0000)
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

lib/AST/QualTypeNames.cpp
unittests/Tooling/QualTypeNamesTest.cpp

index ce01f66297bce70239517f6ee8afcd3a7bda35bb..f28f00171cce30ba1df29358fc6517c786508a22 100644 (file)
@@ -379,6 +379,19 @@ QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx,
     return QT;
   }
 
+  if (auto *MPT = dyn_cast<MemberPointerType>(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<ReferenceType>(QT.getTypePtr())) {
index 0b85beb1062906a64be763bbfdfb785c4e7bbde8..b6c302977876314a3a330d8c02b59be4a6ed169e 100644 (file)
@@ -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 <typename T>\n"
       "    using Alias = CCC<T>;\n"
       "    Alias<int> 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"