[clang] [clang][AST] Preserve qualifiers in getFullyQualifiedType for AutoType (PR #187717)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 20 07:59:35 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Devajith (devajithvs)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/187717.diff
2 Files Affected:
- (modified) clang/lib/AST/QualTypeNames.cpp (+8-2)
- (modified) clang/test/Interpreter/pretty-print.cpp (+4)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/187717
More information about the cfe-commits
mailing list