Skip to content

Commit

Permalink
Don't emit -Wnullability-completeness warnings on weak Objective-…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
mwyman committed Oct 21, 2022
1 parent e5f6ad2 commit 34020d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 7 additions & 2 deletions clang/lib/Sema/SemaType.cpp
Expand Up @@ -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;
}

Expand Down
8 changes: 2 additions & 6 deletions clang/test/SemaObjCXX/Inputs/nullability-consistency-2.h
Expand Up @@ -19,13 +19,9 @@ void g3(const
@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

0 comments on commit 34020d3

Please sign in to comment.