mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 06:26:08 +00:00

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 cannot 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 moves that code to the upstream clang repository. rdar://28937548 Differential Revision: https://reviews.llvm.org/D25993 llvm-svn: 285391
37 lines
1.1 KiB
Objective-C
37 lines
1.1 KiB
Objective-C
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
|
|
// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s
|
|
// rdar://16560476
|
|
|
|
__attribute__((objc_subclassing_restricted))
|
|
@interface Leaf // okay
|
|
@end
|
|
|
|
__attribute__((objc_subclassing_restricted))
|
|
@interface SubClassOfLeaf : Leaf // expected-note {{class is declared here}}
|
|
@end
|
|
|
|
|
|
@interface SubClass : SubClassOfLeaf // expected-error {{cannot subclass a class that was declared with the 'objc_subclassing_restricted' attribute}}
|
|
@end
|
|
|
|
__attribute__((objc_root_class))
|
|
@interface PlainRoot
|
|
@end
|
|
|
|
__attribute__((objc_subclassing_restricted))
|
|
@interface Sub2Class : PlainRoot // okay
|
|
@end
|
|
|
|
// rdar://28753587
|
|
__attribute__((objc_subclassing_restricted))
|
|
@interface SuperImplClass // expected-note {{class is declared here}}
|
|
@end
|
|
@implementation SuperImplClass
|
|
@end
|
|
|
|
__attribute__((objc_subclassing_restricted))
|
|
@interface SubImplClass : SuperImplClass
|
|
@end
|
|
@implementation SubImplClass // expected-error {{cannot subclass a class that was declared with the 'objc_subclassing_restricted' attribute}}
|
|
@end
|