[clang] fb7fa27 - Preserve qualifiers when getting fully qualified type

via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 29 19:48:04 PDT 2022


Author: Weverything
Date: 2022-07-29T19:42:54-07:00
New Revision: fb7fa27f92caf10315d3fb7def99affb71b4fe44

URL: https://github.com/llvm/llvm-project/commit/fb7fa27f92caf10315d3fb7def99affb71b4fe44
DIFF: https://github.com/llvm/llvm-project/commit/fb7fa27f92caf10315d3fb7def99affb71b4fe44.diff

LOG: Preserve qualifiers when getting fully qualified type

15f3cd6bfc670ba6106184a903eb04be059e5977 moved the handling of UsingType
to a later point in the function getFullyQualifiedType.  This moved it
after the removal of an ElaboratedType and its qualifiers.  However,
the qualifiers were not added back, causing the fully qualified type to
have a qualifier mismatch with the original type.  Make sure the
qualifers are added before continuing to fully qualify the type.

Added: 
    

Modified: 
    clang/lib/AST/QualTypeNames.cpp
    clang/unittests/Tooling/QualTypeNamesTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/QualTypeNames.cpp b/clang/lib/AST/QualTypeNames.cpp
index 8c736a7181605..1bfe9996e44c3 100644
--- a/clang/lib/AST/QualTypeNames.cpp
+++ b/clang/lib/AST/QualTypeNames.cpp
@@ -452,8 +452,8 @@ QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx,
   // We don't consider the alias introduced by `using a::X` as a new type.
   // The qualified name is still a::X.
   if (const auto *UT = QT->getAs<UsingType>()) {
-    return getFullyQualifiedType(UT->getUnderlyingType(), Ctx,
-                                 WithGlobalNsPrefix);
+    QT = Ctx.getQualifiedType(UT->getUnderlyingType(), PrefixQualifiers);
+    return getFullyQualifiedType(QT, Ctx, WithGlobalNsPrefix);
   }
 
   // Create a nested name specifier if needed.

diff  --git a/clang/unittests/Tooling/QualTypeNamesTest.cpp b/clang/unittests/Tooling/QualTypeNamesTest.cpp
index 4e5156000d668..686d189cf69eb 100644
--- a/clang/unittests/Tooling/QualTypeNamesTest.cpp
+++ b/clang/unittests/Tooling/QualTypeNamesTest.cpp
@@ -287,4 +287,14 @@ TEST(QualTypeNameTest, AnonStrucs) {
                         } anon_st;)");
 }
 
+TEST(QualTypeNameTest, ConstUsing) {
+  TypeNameVisitor ConstUsing;
+  ConstUsing.ExpectedQualTypeNames["param1"] = "const A::S &";
+  ConstUsing.ExpectedQualTypeNames["param2"] = "const A::S";
+  ConstUsing.runOver(R"(namespace A {
+                          class S {};
+                        }
+                        using ::A::S;
+                        void foo(const S& param1, const S param2);)");
+}
 }  // end anonymous namespace


        


More information about the cfe-commits mailing list