r240155 - Implement the 'null_resettable' attribute for Objective-C properties.

Aaron Ballman aaron at aaronballman.com
Mon Jun 22 11:52:00 PDT 2015


On Mon, Jun 22, 2015 at 2:13 PM, Douglas Gregor <dgregor at apple.com> wrote:
>
> On Jun 20, 2015, at 12:10 PM, Aaron Ballman <aaron at aaronballman.com> wrote:
>
> On Fri, Jun 19, 2015 at 2:14 PM, Douglas Gregor <dgregor at apple.com> wrote:
>
> +  for (const auto *propertyImpl : impDecl->property_impls()) {
> +    const auto *property = propertyImpl->getPropertyDecl();
> +
> +    // Warn about null_resettable properties with synthesized setters,
> +    // because the setter won't properly handle nil.
> +    if (propertyImpl->getPropertyImplementation()
> +          == ObjCPropertyImplDecl::Synthesize &&
> +        (property->getPropertyAttributes() &
> +         ObjCPropertyDecl::OBJC_PR_null_resettable) &&
>
>
> The more I see the bitwise tests, the more I wonder if having a
> propertyAttributeIsSet() function might make sense?
>
>
> Probably, yes.
>
>
> +        property->getGetterMethodDecl() &&
> +        property->getSetterMethodDecl()) {
> +      auto *getterMethod = property->getGetterMethodDecl();
> +      auto *setterMethod = property->getSetterMethodDecl();
> +      if (!impDecl->getInstanceMethod(setterMethod->getSelector()) &&
> +          !impDecl->getInstanceMethod(getterMethod->getSelector())) {
> +        SourceLocation loc = propertyImpl->getLocation();
> +        if (loc.isInvalid())
> +          loc = impDecl->getLocStart();
>
>
> Under what circumstances would loc be invalid here? (I may simply be
> unfamiliar with ObjC and that's not a problem.)
>
>
> Getters and setters can be synthesized by the @implementation, which means
> they won’t have useful source locations.

Ah, thank you for that explanation!

~Aaron

>
> (Comments appreciated and cleanup commits coming, thanks!)
>
> - Doug
>




More information about the cfe-commits mailing list