llvm-project

Форк
0
/
objcxx11-attributes.mm 
66 строк · 2.8 Кб
1
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2

3
@interface X {}
4
+ (X*) alloc;
5
- (X*) init;
6
- (int) getSize;
7
- (void) setSize: (int) size;
8
- (X*) getSelf;
9
@end
10

11
void f(X *noreturn) {
12
  // An array size which is computed by a message send is OK.
13
  int a[ [noreturn getSize] ]; // expected-warning {{variable length arrays in C++ are a Clang extension}}
14

15
  // ... but is interpreted as an attribute where possible.
16
  int b[ [noreturn] ]; // expected-error {{'noreturn' attribute only applies to functions}}
17

18
  int c[ [noreturn getSize] + 1 ]; // expected-warning {{variable length arrays in C++ are a Clang extension}}
19

20
  // An array size which is computed by a lambda is not OK.
21
  int d[ [noreturn] { return 3; } () ]; // expected-error {{expected ']'}} expected-error {{'noreturn' attribute only applies to functions}}
22

23
  // A message send which contains a message send is OK.
24
  [ [ X alloc ] init ];
25
  [ [ int(), noreturn getSelf ] getSize ]; // expected-warning {{left operand of comma operator has no effect}}
26

27
  // A message send which contains a lambda is OK.
28
  [ [noreturn] { return noreturn; } () setSize: 4 ];
29
  [ [bitand] { return noreturn; } () setSize: 5 ];
30
  [[[[] { return [ X alloc ]; } () init] getSelf] getSize];
31

32
  // An attribute is OK.
33
  [[]];
34
  [[int(), noreturn]]; // expected-warning {{unknown attribute 'int' ignored}} \
35
  // expected-error {{'noreturn' attribute cannot be applied to a statement}}
36
  [[class, test(foo 'x' bar),,,]]; // expected-warning {{unknown attribute 'test' ignored}}\
37
  // expected-warning {{unknown attribute 'class' ignored}}
38

39
  [[bitand, noreturn]]; // expected-error {{'noreturn' attribute cannot be applied to a statement}} \
40
  expected-warning {{unknown attribute 'bitand' ignored}} 
41

42
  // FIXME: Suppress vexing parse warning
43
  [[gnu::noreturn]]int(e)(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} 
44
  int e2(); // expected-warning {{interpreted as a function declaration}} expected-note{{}}
45

46
  // A function taking a noreturn function.
47
  int(f)([[gnu::noreturn]] int ()); // expected-note {{here}}
48
  f(e);
49
  f(e2); // expected-error {{cannot initialize a parameter of type 'int (*)() __attribute__((noreturn))' with an lvalue of type 'int ()'}}
50

51
  // Variables initialized by a message send.
52
  int(g)([[noreturn getSelf] getSize]);
53
  int(h)([[noreturn]{return noreturn;}() getSize]);
54

55
  int i = g + h;
56
}
57

58
template<typename...Ts> void f(Ts ...x) {
59
  [[test::foo(bar, baz)...]]; // expected-error {{attribute 'foo' cannot be used as an attribute pack}} \
60
  // expected-warning {{unknown attribute 'foo' ignored}}
61

62
  [[used(x)...]]; // expected-error {{attribute 'used' cannot be used as an attribute pack}} \
63
  // expected-warning {{unknown attribute 'used' ignored}}
64

65
  [[x...] { return [ X alloc ]; }() init];
66
}
67

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

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

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

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