[clang] [clang][AST] Preserve qualifiers in getFullyQualifiedType for AutoType (PR #187717)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 20 08:14:20 PDT 2026
https://github.com/devajithvs updated https://github.com/llvm/llvm-project/pull/187717
>From 81e9fc34bd6908ba89976f0924ee20f2f6aedd49 Mon Sep 17 00:00:00 2001
From: Devajith Valaparambil Sreeramaswamy
<devajith.valaparambil.sreeramaswamy at cern.ch>
Date: Fri, 20 Mar 2026 15:30:20 +0100
Subject: [PATCH] [clang][AST] Preserve qualifiers in getFullyQualifiedType for
AutoType
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.
---
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 cfe-commits
mailing list