Skip to content

Commit a185a6e

Browse files
[ObjC] Mark classes that shouldn't be subclassed as such.
Several of the classes vended by the runtime don't really support subclassing, so mark them as such to get compiler enforcement just in case. PiperOrigin-RevId: 505221732
1 parent 55d2123 commit a185a6e

File tree

8 files changed

+81
-5
lines changed

8 files changed

+81
-5
lines changed

objectivec/GPBArray.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
4848
*
4949
* @note This class is not meant to be subclassed.
5050
**/
51+
__attribute__((objc_subclassing_restricted))
5152
@interface GPBInt32Array : NSObject <NSCopying>
5253

5354
/** The number of elements contained in the array. */
@@ -222,6 +223,7 @@ NS_ASSUME_NONNULL_BEGIN
222223
*
223224
* @note This class is not meant to be subclassed.
224225
**/
226+
__attribute__((objc_subclassing_restricted))
225227
@interface GPBUInt32Array : NSObject <NSCopying>
226228

227229
/** The number of elements contained in the array. */
@@ -396,6 +398,7 @@ NS_ASSUME_NONNULL_BEGIN
396398
*
397399
* @note This class is not meant to be subclassed.
398400
**/
401+
__attribute__((objc_subclassing_restricted))
399402
@interface GPBInt64Array : NSObject <NSCopying>
400403

401404
/** The number of elements contained in the array. */
@@ -570,6 +573,7 @@ NS_ASSUME_NONNULL_BEGIN
570573
*
571574
* @note This class is not meant to be subclassed.
572575
**/
576+
__attribute__((objc_subclassing_restricted))
573577
@interface GPBUInt64Array : NSObject <NSCopying>
574578

575579
/** The number of elements contained in the array. */
@@ -744,6 +748,7 @@ NS_ASSUME_NONNULL_BEGIN
744748
*
745749
* @note This class is not meant to be subclassed.
746750
**/
751+
__attribute__((objc_subclassing_restricted))
747752
@interface GPBFloatArray : NSObject <NSCopying>
748753

749754
/** The number of elements contained in the array. */
@@ -918,6 +923,7 @@ NS_ASSUME_NONNULL_BEGIN
918923
*
919924
* @note This class is not meant to be subclassed.
920925
**/
926+
__attribute__((objc_subclassing_restricted))
921927
@interface GPBDoubleArray : NSObject <NSCopying>
922928

923929
/** The number of elements contained in the array. */
@@ -1092,6 +1098,7 @@ NS_ASSUME_NONNULL_BEGIN
10921098
*
10931099
* @note This class is not meant to be subclassed.
10941100
**/
1101+
__attribute__((objc_subclassing_restricted))
10951102
@interface GPBBoolArray : NSObject <NSCopying>
10961103

10971104
/** The number of elements contained in the array. */
@@ -1266,6 +1273,7 @@ NS_ASSUME_NONNULL_BEGIN
12661273
*
12671274
* @note This class is not meant to be subclassed.
12681275
**/
1276+
__attribute__((objc_subclassing_restricted))
12691277
@interface GPBEnumArray : NSObject <NSCopying>
12701278

12711279
/** The number of elements contained in the array. */
@@ -1583,6 +1591,7 @@ NS_ASSUME_NONNULL_END
15831591
//% *
15841592
//% * @note This class is not meant to be subclassed.
15851593
//% **/
1594+
//%__attribute__((objc_subclassing_restricted))
15861595
//%@interface GPB##NAME##Array : NSObject <NSCopying>
15871596
//%
15881597
//%/** The number of elements contained in the array. */
@@ -1675,6 +1684,7 @@ NS_ASSUME_NONNULL_END
16751684
//% *
16761685
//% * @note This class is not meant to be subclassed.
16771686
//% **/
1687+
//%__attribute__((objc_subclassing_restricted))
16781688
//%@interface GPB##NAME##Array : NSObject <NSCopying>
16791689
//%
16801690
//%/** The number of elements contained in the array. */

objectivec/GPBCodedInputStream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ CF_EXTERN_C_END
8383
*
8484
* @note Subclassing of @c GPBCodedInputStream is NOT supported.
8585
**/
86+
__attribute__((objc_subclassing_restricted))
8687
@interface GPBCodedInputStream : NSObject
8788

8889
/**

objectivec/GPBCodedOutputStream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extern NSString *const GPBCodedOutputStreamException_WriteFailed;
6363
*
6464
* @note Subclassing of GPBCodedOutputStream is NOT supported.
6565
**/
66+
__attribute__((objc_subclassing_restricted))
6667
@interface GPBCodedOutputStream : NSObject
6768

6869
/**

objectivec/GPBDescriptor.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
6262
/**
6363
* Describes a proto message.
6464
**/
65-
@interface GPBDescriptor : NSObject <NSCopying>
65+
__attribute__((objc_subclassing_restricted))
66+
@interface GPBDescriptor : NSObject<NSCopying>
6667

6768
- (instancetype)init NS_UNAVAILABLE;
6869
+ (instancetype)new NS_UNAVAILABLE;
@@ -124,6 +125,7 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
124125
/**
125126
* Describes a proto file.
126127
**/
128+
__attribute__((objc_subclassing_restricted))
127129
@interface GPBFileDescriptor : NSObject
128130

129131
- (instancetype)init NS_UNAVAILABLE;
@@ -149,6 +151,7 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
149151
/**
150152
* Describes a oneof field.
151153
**/
154+
__attribute__((objc_subclassing_restricted))
152155
@interface GPBOneofDescriptor : NSObject
153156

154157
- (instancetype)init NS_UNAVAILABLE;
@@ -182,6 +185,7 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
182185
/**
183186
* Describes a proto field.
184187
**/
188+
__attribute__((objc_subclassing_restricted))
185189
@interface GPBFieldDescriptor : NSObject
186190

187191
- (instancetype)init NS_UNAVAILABLE;
@@ -234,6 +238,7 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
234238
/**
235239
* Describes a proto enum.
236240
**/
241+
__attribute__((objc_subclassing_restricted))
237242
@interface GPBEnumDescriptor : NSObject
238243

239244
- (instancetype)init NS_UNAVAILABLE;
@@ -329,7 +334,8 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
329334
/**
330335
* Describes a proto extension.
331336
**/
332-
@interface GPBExtensionDescriptor : NSObject <NSCopying>
337+
__attribute__((objc_subclassing_restricted))
338+
@interface GPBExtensionDescriptor : NSObject<NSCopying>
333339

334340
- (instancetype)init NS_UNAVAILABLE;
335341
+ (instancetype)new NS_UNAVAILABLE;

0 commit comments

Comments
 (0)