aboutsummaryrefslogtreecommitdiff
path: root/clang/test/Analysis/pragma-diag-control.cpp
blob: 470960c030d0f9492f3bd8837ba9c4a9a7114e1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// RUN: %clang_cc1 -fsyntax-only -verify -Werror=unreachable-code-aggressive %s

// Test that analysis-based warnings honor #pragma diagnostic controls.

struct [[clang::consumable(unconsumed)]] Linear {
  [[clang::return_typestate(unconsumed)]]
  Linear() {}
  [[clang::callable_when(consumed)]]
  ~Linear() {}
};

int a() {	
  Linear l;
  return 0; // No -Wconsumed diagnostic, analysis is not enabled.
  return 1; // expected-error {{'return' will never be executed}}
}

#pragma clang diagnostic push
#pragma clang diagnostic error "-Wconsumed"
int b() {
  Linear l;
  return 0;  // expected-error {{invalid invocation of method '~Linear' on object 'l' while it is in the 'unconsumed' state}}
  return 1;  // expected-error {{'return' will never be executed}}
}
#pragma clang diagnostic pop

int c() {
#pragma clang diagnostic push
#pragma clang diagnostic error "-Wconsumed"
  Linear l;
  return 0; // expected-error {{invalid invocation of method '~Linear' on object 'l' while it is in the 'unconsumed' state}}
  return 1; // expected-error {{'return' will never be executed}}
#pragma clang diagnostic pop
}

int d() {
#pragma clang diagnostic push
#pragma clang diagnostic error "-Wconsumed"
#pragma clang diagnostic ignored "-Wunreachable-code-aggressive"
  Linear l;
  return 0; // expected-error {{invalid invocation of method '~Linear' on object 'l' while it is in the 'unconsumed' state}}
  return 1; // Diagnostic is ignored
}
#pragma clang diagnostic pop

int e() {
#pragma clang diagnostic push
#pragma clang diagnostic error "-Wconsumed"
#pragma clang diagnostic ignored "-Wunreachable-code-aggressive"
  Linear l;
  return 0; // expected-error {{invalid invocation of method '~Linear' on object 'l' while it is in the 'unconsumed' state}}
  return 1; // Diagnostic is ignored
#pragma clang diagnostic pop
}

int f() {
  Linear l;
  return 0; // No -Wconsumed diagnostic, analysis is not enabled
  return 1; // expected-error {{'return' will never be executed}}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code-aggressive"
}
#pragma clang diagnostic pop	

int g() {
  Linear l;
  return 0; // No -Wconsumed diagnostic, the diagnostic generated at } is not enabled on this line.
  return 1; // expected-error {{'return' will never be executed}}
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wconsumed"
}
#pragma clang diagnostic pop

int h() {
#pragma clang diagnostic push
#pragma clang diagnostic error "-Wconsumed"
#pragma clang diagnostic ignored "-Wunreachable-code-aggressive"
#pragma clang diagnostic pop

  Linear l;
  return 0; // No -Wconsumed diagnostic, the diagnostic generated at } is not enabled on this line.
  return 1; // expected-error {{'return' will never be executed}}
}