[clang] 34020d3 - Don't emit `-Wnullability-completeness` warnings on `weak` Objective-C properties.
Michael Wyman via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 20 22:43:04 PDT 2022
Author: Michael Wyman
Date: 2022-10-20T22:42:24-07:00
New Revision: 34020d39b8a116770aad0b5ad1a450e6e22da5cd
URL: https://github.com/llvm/llvm-project/commit/34020d39b8a116770aad0b5ad1a450e6e22da5cd
DIFF: https://github.com/llvm/llvm-project/commit/34020d39b8a116770aad0b5ad1a450e6e22da5cd.diff
LOG: Don't emit `-Wnullability-completeness` warnings on `weak` Objective-C properties.
Zeroing weak references are by definition `nullable`, and adding
`nonnull` or `_Nullable` yields a mutual-exclusivity error. When
`-Wnullability-completeness` is enabled, however, non-audited header
regions require adding the `nullable` property keyword to avoid a
warning. This should be unnecessary, since it restates known nullability
of the `weak` property.
Additionally, the fix-it hints are both non-idiomatic Objective-C
(adding `_Nullable` to the property's pointer type rather than in the
`@property` attributes) and suggest the option of adding `_Nonnull`,
which would be an error.
Differential Revision: https://reviews.llvm.org/D128031
Added:
Modified:
clang/lib/Sema/SemaType.cpp
clang/test/SemaObjCXX/Inputs/nullability-consistency-2.h
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 6bd973e2f0423..3fe85a2e837ab 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -4748,8 +4748,13 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
}
// Weak properties are inferred to be nullable.
- if (state.getDeclarator().isObjCWeakProperty() && inAssumeNonNullRegion) {
- inferNullability = NullabilityKind::Nullable;
+ if (state.getDeclarator().isObjCWeakProperty()) {
+ // Weak properties cannot be nonnull, and should not complain about
+ // missing nullable attributes during completeness checks.
+ complainAboutMissingNullability = CAMN_No;
+ if (inAssumeNonNullRegion) {
+ inferNullability = NullabilityKind::Nullable;
+ }
break;
}
diff --git a/clang/test/SemaObjCXX/Inputs/nullability-consistency-2.h b/clang/test/SemaObjCXX/Inputs/nullability-consistency-2.h
index 84a1369618af0..6d767998fd5b9 100644
--- a/clang/test/SemaObjCXX/Inputs/nullability-consistency-2.h
+++ b/clang/test/SemaObjCXX/Inputs/nullability-consistency-2.h
@@ -19,13 +19,9 @@ void g3(const
@property (retain,nullable) SomeClass *property2;
- (nullable SomeClass *)method1;
- (void)method2:(nonnull SomeClass *)param;
- at property (readonly, weak) SomeClass *property3; // expected-warning{{missing a nullability type specifier}}
-// expected-note at -1 {{insert '_Nullable' if the pointer may be null}}
-// expected-note at -2 {{insert '_Nonnull' if the pointer should never be null}}
+ at property (readonly, weak) SomeClass *property3;
@end
@interface SomeClass ()
- at property (readonly, weak) SomeClass *property4; // expected-warning{{missing a nullability type specifier}}
-// expected-note at -1 {{insert '_Nullable' if the pointer may be null}}
-// expected-note at -2 {{insert '_Nonnull' if the pointer should never be null}}
+ at property (readonly, weak) SomeClass *property4;
@end
More information about the cfe-commits
mailing list