xref: /llvm-project/clang/test/SemaObjC/check-dup-decls-inside-objc.m (revision 29444f0444c6d3586969fd6fbe49c8188c02c244)
1// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
2// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class -x objective-c++ %s
3
4// Test decls inside Objective-C entities are considered to be duplicates of same-name decls outside of these entities.
5
6@protocol SomeProtocol
7struct InProtocol {}; // expected-note {{previous definition is here}}
8- (union MethodReturnType { int x; float y; })returningMethod; // expected-note {{previous definition is here}}
9#ifdef __cplusplus
10// expected-error@-2 {{'MethodReturnType' cannot be defined in a parameter type}}
11#endif
12@end
13
14@interface Container {
15  struct InInterfaceCurliesWithField {} field; // expected-note {{previous definition is here}}
16  union InInterfaceCurlies { int x; float y; }; // expected-note {{previous definition is here}}
17}
18enum InInterface { kX = 0, }; // expected-note {{previous definition is here}}
19#ifdef __cplusplus
20enum class InInterfaceScoped { kXScoped = 0, }; // expected-note {{previous definition is here}}
21#endif
22@end
23
24@interface Container(Category)
25union InCategory { int x; float y; }; // expected-note {{previous definition is here}}
26@end
27
28@interface Container() {
29  enum InExtensionCurliesWithField: int { kY = 1, } extensionField; // expected-note {{previous definition is here}}
30  struct InExtensionCurlies {}; // expected-note {{previous definition is here}}
31}
32union InExtension { int x; float y; }; // expected-note {{previous definition is here}}
33@end
34
35@implementation Container {
36  union InImplementationCurliesWithField { int x; float y; } implField; // expected-note {{previous definition is here}}
37  enum InImplementationCurlies { kZ = 2, }; // expected-note {{previous definition is here}}
38}
39struct InImplementation {}; // expected-note {{previous definition is here}}
40@end
41
42@implementation Container(Category)
43enum InCategoryImplementation { kW = 3, }; // expected-note {{previous definition is here}}
44@end
45
46
47struct InProtocol { int a; }; // expected-error {{redefinition of 'InProtocol'}}
48union MethodReturnType { int a; long b; }; // expected-error {{redefinition of 'MethodReturnType'}}
49
50struct InInterfaceCurliesWithField { int a; }; // expected-error {{redefinition of 'InInterfaceCurliesWithField'}}
51union InInterfaceCurlies { int a; long b; }; // expected-error {{redefinition of 'InInterfaceCurlies'}}
52enum InInterface { kA = 10, }; // expected-error {{redefinition of 'InInterface'}}
53#ifdef __cplusplus
54enum class InInterfaceScoped { kAScoped = 10, }; // expected-error {{redefinition of 'InInterfaceScoped'}}
55#endif
56
57union InCategory { int a; long b; }; // expected-error {{redefinition of 'InCategory'}}
58
59enum InExtensionCurliesWithField: int { kB = 11, }; // expected-error {{redefinition of 'InExtensionCurliesWithField'}}
60struct InExtensionCurlies { int a; }; // expected-error {{redefinition of 'InExtensionCurlies'}}
61union InExtension { int a; long b; }; // expected-error {{redefinition of 'InExtension'}}
62
63union InImplementationCurliesWithField { int a; long b; }; // expected-error {{redefinition of 'InImplementationCurliesWithField'}}
64enum InImplementationCurlies { kC = 12, }; // expected-error {{redefinition of 'InImplementationCurlies'}}
65struct InImplementation { int a; }; // expected-error {{redefinition of 'InImplementation'}}
66
67enum InCategoryImplementation { kD = 13, }; // expected-error {{redefinition of 'InCategoryImplementation'}}
68