[clang] [clang] fix -Wnullability-completeness false-positive in dependent code (PR #88727)
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 15 06:03:53 PDT 2024
https://github.com/sam-mccall created https://github.com/llvm/llvm-project/pull/88727
The intent was that smart-pointers do not participate in completeness
checks, but we failed to capture dependent `unique_ptr<T>`, which is not
a RecordType but a TemplateSpecializationType.
>From f1bea480b599b431f67df432d130e537d32abe86 Mon Sep 17 00:00:00 2001
From: Sam McCall <sam.mccall at gmail.com>
Date: Mon, 15 Apr 2024 14:56:33 +0200
Subject: [PATCH] [clang] fix -Wnullability-completeness false-positive in
dependent code
The intent was that smart-pointers do not participate in completeness
checks, but we failed to capture dependent `unique_ptr<T>`, which is not
a RecordType but a TemplateSpecializationType.
---
clang/lib/Sema/SemaType.cpp | 3 ++-
clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h | 4 ++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 404c4e8e31b558..6ac8a9433c701b 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -4728,7 +4728,8 @@ static bool shouldHaveNullability(QualType T) {
// It's unclear whether the pragma's behavior is useful for C++.
// e.g. treating type-aliases and template-type-parameters differently
// from types of declarations can be surprising.
- !isa<RecordType>(T->getCanonicalTypeInternal());
+ !isa<RecordType, TemplateSpecializationType>(
+ T->getCanonicalTypeInternal());
}
static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
diff --git a/clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h b/clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h
index a28532e5d71668..5ff974af57f49b 100644
--- a/clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h
+++ b/clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h
@@ -5,3 +5,7 @@ void f1(int * _Nonnull);
void f2(Smart); // OK, not required on smart-pointer types
using Alias = Smart;
void f3(Alias);
+
+template <class T> class _Nullable SmartTmpl;
+void f2(SmartTmpl<int>);
+template <class T> void f2(SmartTmpl<T>);
More information about the cfe-commits
mailing list