mwyman created this revision.
mwyman added reviewers: dmaclach, stephanemoore.
mwyman added a project: clang.
Herald added a project: All.
mwyman requested review of this revision.
Herald added a subscriber: cfe-commits.
Zeroing weak references are by definition `nullable`, and adding `nonnull` or
`_Nonnull` yields a mutual-exclusivity error. However, when
`-Wnullability-completeness` is enabled, in non-audited header regions it's
necessary to add the `nullable` property keyword to avoid a warning. It should
not be necessary to add code clutter to restate the nullability of a `weak`
property even under `-Wnullability-completeness`.
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).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D128031
Files:
clang/lib/Sema/SemaType.cpp
clang/test/SemaObjCXX/Inputs/nullability-consistency-2.h
Index: clang/test/SemaObjCXX/Inputs/nullability-consistency-2.h
===================================================================
--- clang/test/SemaObjCXX/Inputs/nullability-consistency-2.h
+++ clang/test/SemaObjCXX/Inputs/nullability-consistency-2.h
@@ -19,13 +19,9 @@
@property (retain,nullable) SomeClass *property2;
- (nullable SomeClass *)method1;
- (void)method2:(nonnull SomeClass *)param;
-@property (readonly, weak) SomeClass *property3; // expected-warning{{missing
a nullability type specifier}}
-// expected-note@-1 {{insert '_Nullable' if the pointer may be null}}
-// expected-note@-2 {{insert '_Nonnull' if the pointer should never be null}}
+@property (readonly, weak) SomeClass *property3;
@end
@interface SomeClass ()
-@property (readonly, weak) SomeClass *property4; // expected-warning{{missing
a nullability type specifier}}
-// expected-note@-1 {{insert '_Nullable' if the pointer may be null}}
-// expected-note@-2 {{insert '_Nonnull' if the pointer should never be null}}
+@property (readonly, weak) SomeClass *property4;
@end
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4683,8 +4683,13 @@
}
// 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;
}
Index: clang/test/SemaObjCXX/Inputs/nullability-consistency-2.h
===================================================================
--- clang/test/SemaObjCXX/Inputs/nullability-consistency-2.h
+++ clang/test/SemaObjCXX/Inputs/nullability-consistency-2.h
@@ -19,13 +19,9 @@
@property (retain,nullable) SomeClass *property2;
- (nullable SomeClass *)method1;
- (void)method2:(nonnull SomeClass *)param;
-@property (readonly, weak) SomeClass *property3; // expected-warning{{missing a nullability type specifier}}
-// expected-note@-1 {{insert '_Nullable' if the pointer may be null}}
-// expected-note@-2 {{insert '_Nonnull' if the pointer should never be null}}
+@property (readonly, weak) SomeClass *property3;
@end
@interface SomeClass ()
-@property (readonly, weak) SomeClass *property4; // expected-warning{{missing a nullability type specifier}}
-// expected-note@-1 {{insert '_Nullable' if the pointer may be null}}
-// expected-note@-2 {{insert '_Nonnull' if the pointer should never be null}}
+@property (readonly, weak) SomeClass *property4;
@end
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4683,8 +4683,13 @@
}
// 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;
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits