[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:05 PDT 2026
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/187872
Backport 1f9c54a
Requested by: @devajithvs
>From a5fa2012515a595f2357b9033f2d7cfb7ae1fd2e Mon Sep 17 00:00:00 2001
From: Devajith <devajith.valaparambil.sreeramaswamy at cern.ch>
Date: Sat, 21 Mar 2026 09:22:20 +0100
Subject: [PATCH] [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.
(cherry picked from commit 1f9c54a15a87f72ca45fb47ec006d1eae63f4eb0)
---
clang/lib/AST/QualTypeNames.cpp | 10 ++++++++--
clang/test/Interpreter/pretty-print.cpp | 4 ++++
2 files changed, 12 insertions(+), 2 deletions(-)
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
More information about the llvm-branch-commits
mailing list