Author: Devajith Date: 2026-03-21T09:22:20+01:00 New Revision: 1f9c54a15a87f72ca45fb47ec006d1eae63f4eb0
URL: https://github.com/llvm/llvm-project/commit/1f9c54a15a87f72ca45fb47ec006d1eae63f4eb0 DIFF: https://github.com/llvm/llvm-project/commit/1f9c54a15a87f72ca45fb47ec006d1eae63f4eb0.diff LOG: [clang][AST] Preserve qualifiers in getFullyQualifiedType for AutoType (#187717) A previous change (86c4e96) did not preserve qualifiers attached to the AutoType QualType when the type was deduced. For an AutoType after `getDeducedType()`, qualifiers from the original QualType were dropped. Preserve and reapply them to the deduced type. Added: Modified: clang/lib/AST/QualTypeNames.cpp clang/test/Interpreter/pretty-print.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/QualTypeNames.cpp b/clang/lib/AST/QualTypeNames.cpp index 9e3885e100c6b..7cdee52acce3f 100644 --- a/clang/lib/AST/QualTypeNames.cpp +++ b/clang/lib/AST/QualTypeNames.cpp @@ -370,9 +370,15 @@ NestedNameSpecifier createNestedNameSpecifier(const ASTContext &Ctx, QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx, bool WithGlobalNsPrefix) { // Use the underlying deduced type for AutoType - if (const auto *AT = dyn_cast<AutoType>(QT.getTypePtr())) - if (AT->isDeduced()) + if (const auto *AT = dyn_cast<AutoType>(QT.getTypePtr())) { + if (AT->isDeduced()) { + // Get the qualifiers. + Qualifiers Quals = QT.getQualifiers(); QT = AT->getDeducedType(); + // Add back the qualifiers. + QT = Ctx.getQualifiedType(QT, Quals); + } + } // In case of myType* we need to strip the pointer first, fully // qualify and attach the pointer once again. diff --git a/clang/test/Interpreter/pretty-print.cpp b/clang/test/Interpreter/pretty-print.cpp index f0548358d65db..ef0ee8e233c28 100644 --- a/clang/test/Interpreter/pretty-print.cpp +++ b/clang/test/Interpreter/pretty-print.cpp @@ -69,6 +69,10 @@ namespace Outer { template<class T> struct Bar {}; } auto y = Outer::Bar<int>(); y // CHECK-NEXT: (Outer::Bar<int> &) @0x{{[0-9a-f]+}} +// Check that const is preserved +const auto z = Outer::Foo(); z +// CHECK-NEXT: (const Outer::Foo &) @0x{{[0-9a-f]+}} + // int i = 12; // int &iref = i; // iref _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
