Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang] fix -Wnullability-completeness false-positive in dependent code #88727

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

sam-mccall
Copy link
Collaborator

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.

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.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Apr 15, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 15, 2024

@llvm/pr-subscribers-clang

Author: Sam McCall (sam-mccall)

Changes

The intent was that smart-pointers do not participate in completeness
checks, but we failed to capture dependent unique_ptr&lt;T&gt;, which is not
a RecordType but a TemplateSpecializationType.


Full diff: https://github.com/llvm/llvm-project/pull/88727.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaType.cpp (+2-1)
  • (modified) clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h (+4)
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>);

@sam-mccall sam-mccall merged commit 7257c37 into llvm:main Apr 18, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants