[llvm-branch-commits] [clang] release/22.x: [clang][AST] Preserve qualifiers in getFullyQualifiedType for AutoType (#187717) (PR #187872)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Mar 21 10:23:45 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (llvmbot)
<details>
<summary>Changes</summary>
Backport 1f9c54a
Requested by: @<!-- -->devajithvs
---
Full diff: https://github.com/llvm/llvm-project/pull/187872.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/187872
More information about the llvm-branch-commits
mailing list