This is an archive of the discontinued LLVM Phabricator instance.

[Objective-C] Add objc_subclassing_restricted attribute
ClosedPublic

Authored by arphaman on Oct 26 2016, 8:24 AM.

Details

Summary

This patch adds an objc_subclassing_restricted attribute into clang. This attribute acts similarly to 'final' - Objective-C classes with this attribute can't be subclassed. However, @interface declarations that have objc_subclassing_restricted but don't have @implementation are allowed to inherit other @interface declarations with objc_subclassing_restricted. This is needed to describe the Swift class hierarchy in clang while making sure that the Objective-C classes can't subclass the Swift classes.

This attribute is already implemented in a fork of clang that's used for Swift (https://github.com/apple/swift-clang) and this patch migrates that code to the upstream clang repository.

Diff Detail

Repository
rL LLVM

Event Timeline

arphaman updated this revision to Diff 75898.Oct 26 2016, 8:24 AM
arphaman retitled this revision from to [Objective-C] Add objc_subclassing_restricted attribute.
arphaman updated this object.
arphaman set the repository for this revision to rL LLVM.
arphaman added a subscriber: cfe-commits.
jordan_rose edited edge metadata.Oct 26 2016, 10:02 AM

Looks good from my end.

manmanren accepted this revision.Oct 26 2016, 10:27 AM
manmanren added a reviewer: manmanren.
manmanren added a subscriber: manmanren.

LGTM.

Manman

This revision is now accepted and ready to land.Oct 26 2016, 10:27 AM
aaron.ballman requested changes to this revision.Oct 26 2016, 10:33 AM
aaron.ballman edited edge metadata.
aaron.ballman added inline comments.
include/clang/Basic/Attr.td
1291

No new undocumented attributes, please.

include/clang/Basic/DiagnosticSemaKinds.td
785

Please quote the attribute name in the diagnostic; also, this reads a bit strangely. Perhaps: cannot subclass a class that was declared with the 'objc_subclassing_restricted' attribute?

lib/Sema/SemaDeclObjC.cpp
3888

Can use auto here.

This revision now requires changes to proceed.Oct 26 2016, 10:33 AM
arphaman updated this revision to Diff 76019.Oct 27 2016, 6:57 AM
arphaman edited edge metadata.
arphaman marked 3 inline comments as done.

The updated patch adds documentation and modifies the diagnostic message.

aaron.ballman added inline comments.Oct 27 2016, 7:00 AM
lib/Sema/SemaDeclObjC.cpp
3859

Should this be mentioned in the docs?

arphaman added inline comments.Oct 27 2016, 7:06 AM
lib/Sema/SemaDeclObjC.cpp
3859

I think this more of an implementation detail. You typically wouldn't have @interfaces in Objective-C code without corresponding @implementations, so the attribute will act as expected for most cases. As well as that, you typically wouldn't care how Swift interfaces are declared in Objective-C.

aaron.ballman accepted this revision.Oct 27 2016, 7:08 AM
aaron.ballman edited edge metadata.

LGTM

lib/Sema/SemaDeclObjC.cpp
3859

Works for me, thank you for the explanation!

This revision is now accepted and ready to land.Oct 27 2016, 7:08 AM
This revision was automatically updated to reflect the committed changes.