[clang] [AST] Make nullability attributed-type construction const (PR #215756)

via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 12 01:22:51 PDT 2026


https://github.com/StoeckOverflow created https://github.com/llvm/llvm-project/pull/215756

Make the nullability-specific `ASTContext::getAttributedType` overload `const` and remove a now-unneeded `const_cast` from array-decay handling.

This addresses feedback from https://github.com/llvm/llvm-project/pull/215266#discussion_r3751285430.

Reviewers: @j-hui @Xazax-hun @egorzhdan

>From dd939983644bbbd9daec3ec48f498f7c3c219e74 Mon Sep 17 00:00:00 2001
From: stoeckoverflow <dominic-st at gmx.de>
Date: Tue, 11 Aug 2026 15:23:04 +0200
Subject: [PATCH] [AST] Make nullability attributed-type construction const

---
 clang/include/clang/AST/ASTContext.h | 2 +-
 clang/lib/AST/ASTContext.cpp         | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index 763039e690dec..38c2d282c1a6b 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1995,7 +1995,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
                              QualType equivalentType) const;
 
   QualType getAttributedType(NullabilityKind nullability, QualType modifiedType,
-                             QualType equivalentType);
+                             QualType equivalentType) const;
 
   QualType getBTFTagAttributedType(const BTFTypeTagAttr *BTFAttr,
                                    QualType Wrapped) const;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 02a3f88431f58..5b42194a44549 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5795,7 +5795,7 @@ QualType ASTContext::getAttributedType(const Attr *attr, QualType modifiedType,
 
 QualType ASTContext::getAttributedType(NullabilityKind nullability,
                                        QualType modifiedType,
-                                       QualType equivalentType) {
+                                       QualType equivalentType) const {
   switch (nullability) {
   case NullabilityKind::NonNull:
     return getAttributedType(attr::TypeNonNull, modifiedType, equivalentType);
@@ -8195,8 +8195,7 @@ QualType ASTContext::getArrayDecayedType(QualType Ty) const {
 
   // int x[_Nullable] -> int * _Nullable
   if (auto Nullability = Ty->getNullability()) {
-    Result = const_cast<ASTContext *>(this)->getAttributedType(*Nullability,
-                                                               Result, Result);
+    Result = getAttributedType(*Nullability, Result, Result);
   }
   return Result;
 }



More information about the cfe-commits mailing list