llvm-project

Форк
0
/
property-synthesis-error.mm 
104 строки · 3.1 Кб
1
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
2

3
@interface NSArray @end
4

5
@interface NSMutableArray : NSArray @end
6

7
@interface MyClass
8
{
9
  NSMutableArray * _array;
10
}
11

12
@property (readonly) NSMutableArray * array;
13

14
@end
15

16
@interface MyClass ()
17

18
@property (readwrite, retain) NSMutableArray * array;
19

20
@end
21

22
@implementation MyClass
23

24
@synthesize array=_array;
25

26
@end
27

28
int main(void)
29
{
30
  return 0;
31
}
32

33
class TCPPObject
34
{
35
public:
36
 TCPPObject(const TCPPObject& inObj);
37
 TCPPObject();
38
 ~TCPPObject();
39
 TCPPObject& operator=(const TCPPObject& inObj); // expected-note {{'operator=' declared here}}
40
private:
41
 void* fData;
42
};
43

44
class Trivial
45
{
46
public:
47
 Trivial(const Trivial& inObj);
48
 Trivial();
49
 ~Trivial();
50
private:
51
 void* fData;
52
};
53

54
@interface MyDocument
55
{
56
@private
57
 TCPPObject _cppObject;
58
 TCPPObject _ncppObject;
59
 Trivial _tcppObject;
60
}
61
@property (assign, readwrite) const TCPPObject& cppObject;
62
@property (assign, readwrite, nonatomic) const TCPPObject& ncppObject;
63
@property (assign, readwrite) const Trivial& tcppObject;
64
@end
65

66
@implementation MyDocument
67

68
@synthesize cppObject = _cppObject; // expected-error {{atomic property of reference type 'const TCPPObject &' cannot have non-trivial assignment operator}}
69
@synthesize ncppObject = _ncppObject;
70

71
@synthesize tcppObject = _tcppObject;
72
@end
73

74
struct IncompleteStruct; // expected-note 2 {{forward declaration of 'IncompleteStruct'}}
75
struct ConvertToIncomplete { operator IncompleteStruct&(); };
76
@interface SynthIncompleteRef
77
@property (readonly, nonatomic) IncompleteStruct& x; // expected-note {{property declared here}}
78
@property (readonly, nonatomic) IncompleteStruct& y; // expected-note {{property declared here}}
79
@end
80

81
@implementation SynthIncompleteRef // expected-error {{cannot synthesize property 'x' with incomplete type 'IncompleteStruct'}}
82
@synthesize y; // expected-error {{cannot synthesize property 'y' with incomplete type 'IncompleteStruct'}}
83
@end 
84

85

86
// Check error handling for instantiation during property synthesis.
87
template<typename T> class TemplateClass1 {
88
  T *x; // expected-error {{'x' declared as a pointer to a reference of type 'int &'}}
89
};
90
template<typename T> class TemplateClass2 {
91
  TemplateClass2& operator=(TemplateClass1<T>);
92
  TemplateClass2& operator=(TemplateClass2) { T(); } // expected-error {{reference to type 'int' requires an initializer}} \
93
                                                     // expected-note 2 {{implicitly declared private here}} \
94
                                                     // expected-note {{'operator=' declared here}}
95
};
96
__attribute__((objc_root_class)) @interface InterfaceWithTemplateProperties 
97
@property TemplateClass2<int&> intprop;
98
@property TemplateClass2<int&> &floatprop;
99
@end
100
@implementation InterfaceWithTemplateProperties // expected-error 2 {{'operator=' is a private member of 'TemplateClass2<int &>'}} \
101
																								// expected-error {{atomic property of reference type 'TemplateClass2<int &> &' cannot have non-trivial assignment operator}} \
102
																								// expected-note {{in instantiation of template class}} \
103
																								// expected-note {{in instantiation of member function}}
104
@end  
105

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.