1 // UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
3 // RUN: split-file %s %t
4 // RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-mismatch-in-extension.m
5 // RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-mismatch-in-extension.m \
6 // RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
8 // RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-mismatch-in-ivars-number.m
9 // RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-mismatch-in-ivars-number.m \
10 // RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
12 // RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-mismatch-in-methods-protocols.m
13 // RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-mismatch-in-methods-protocols.m \
14 // RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
16 // RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-redecl-in-subclass.m
17 // RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-redecl-in-subclass.m \
18 // RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
20 // RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-redecl-in-implementation.m
21 // RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-10.9 -verify -I%t/include %t/test-redecl-in-implementation.m \
22 // RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
24 // Same class extensions with the same ivars but from different modules aren't considered
25 // an error and they are merged together. Test that differences in extensions and/or ivars
26 // are still reported as errors.
28 //--- include/Interfaces.h
29 @interface NSObject @end
30 @interface ObjCInterface : NSObject
32 @interface ObjCInterfaceLevel2 : ObjCInterface
35 @protocol Protocol1 @end
36 @protocol Protocol2 @end
38 //--- include/IvarsInExtensions.h
39 #import <Interfaces.h>
40 @interface ObjCInterface() {
44 @interface ObjCInterfaceLevel2() {
45 int bitfieldIvarName: 3;
49 //--- include/IvarsInExtensionsWithMethodsProtocols.h
50 #import <Interfaces.h>
51 @interface ObjCInterface() {
52 int methodRelatedIvar;
56 @interface ObjCInterfaceLevel2() <Protocol1> {
57 int protocolRelatedIvar;
61 //--- include/IvarInImplementation.h
62 #import <Interfaces.h>
63 @implementation ObjCInterface {
68 //--- include/module.modulemap
73 module IvarsInExtensions {
74 header "IvarsInExtensions.h"
77 module IvarsInExtensionsWithMethodsProtocols {
78 header "IvarsInExtensionsWithMethodsProtocols.h"
81 module IvarInImplementation {
82 header "IvarInImplementation.h"
87 //--- test-mismatch-in-extension.m
88 // Different ivars with the same name aren't mergeable and constitute an error.
89 #import <Interfaces.h>
90 @interface ObjCInterface() {
91 float ivarName; // expected-note {{previous definition is here}}
94 @interface ObjCInterfaceLevel2() {
95 int bitfieldIvarName: 5; // expected-note {{previous definition is here}}
98 #import <IvarsInExtensions.h>
99 // expected-error@IvarsInExtensions.h:* {{instance variable is already declared}}
100 // expected-error@IvarsInExtensions.h:* {{instance variable is already declared}}
101 @implementation ObjCInterfaceLevel2
105 //--- test-mismatch-in-ivars-number.m
106 // Extensions with different amount of ivars aren't considered to be the same.
107 #import <Interfaces.h>
108 @interface ObjCInterface() {
109 int ivarName; // expected-note {{previous definition is here}}
113 #import <IvarsInExtensions.h>
114 // expected-error@IvarsInExtensions.h:* {{instance variable is already declared}}
115 @implementation ObjCInterface
119 //--- test-mismatch-in-methods-protocols.m
120 // Extensions with different methods or protocols aren't considered to be the same.
121 #import <Interfaces.h>
122 @interface ObjCInterface() {
123 int methodRelatedIvar; // expected-note {{previous definition is here}}
125 - (void)differentTest;
127 @interface ObjCInterfaceLevel2() <Protocol2> {
128 int protocolRelatedIvar; // expected-note {{previous definition is here}}
131 #import <IvarsInExtensionsWithMethodsProtocols.h>
132 // expected-error@IvarsInExtensionsWithMethodsProtocols.h:* {{instance variable is already declared}}
133 // expected-error@IvarsInExtensionsWithMethodsProtocols.h:* {{instance variable is already declared}}
134 @implementation ObjCInterfaceLevel2
138 //--- test-redecl-in-subclass.m
139 // Ivar in superclass extension is not added to a subclass, so the ivar with
140 // the same name in subclass extension is not considered a redeclaration.
141 // expected-no-diagnostics
142 #import <Interfaces.h>
143 @interface ObjCInterfaceLevel2() {
147 #import <IvarsInExtensions.h>
148 @implementation ObjCInterfaceLevel2
152 //--- test-redecl-in-implementation.m
153 // Ivar redeclaration in `@implementation` is always an error and never mergeable.
154 #import <IvarsInExtensions.h>
155 @interface ObjCInterface() {
156 int triggerExtensionIvarDeserialization;
159 #import <IvarInImplementation.h>
160 #if __has_feature(modules)
161 // expected-error@IvarsInExtensions.h:* {{instance variable is already declared}}
162 // expected-note@IvarInImplementation.h:* {{previous definition is here}}
164 // expected-error@IvarInImplementation.h:* {{instance variable is already declared}}
165 // expected-note@IvarsInExtensions.h:* {{previous definition is here}}