| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -Werror=unreachable-code-aggressive %s |
| 2 |
|
| 3 |
// Test that analysis-based warnings honor #pragma diagnostic controls. |
| 4 |
|
| 5 |
struct [[clang::consumable(unconsumed)]] Linear { |
| 6 |
[[clang::return_typestate(unconsumed)]] |
| 7 |
Linear() {} |
| 8 |
[[clang::callable_when(consumed)]] |
| 9 |
~Linear() {} |
| 10 |
}; |
| 11 |
|
| 12 |
int a() { |
| 13 |
Linear l; |
| 14 |
return 0; // No -Wconsumed diagnostic, analysis is not enabled. |
| 15 |
return 1; // expected-error {{'return' will never be executed}} |
| 16 |
} |
| 17 |
|
| 18 |
#pragma clang diagnostic push |
| 19 |
#pragma clang diagnostic error "-Wconsumed" |
| 20 |
int b() { |
| 21 |
Linear l; |
| 22 |
return 0; // expected-error {{invalid invocation of method '~Linear' on object 'l' while it is in the 'unconsumed' state}} |
| 23 |
return 1; // expected-error {{'return' will never be executed}} |
| 24 |
} |
| 25 |
#pragma clang diagnostic pop |
| 26 |
|
| 27 |
int c() { |
| 28 |
#pragma clang diagnostic push |
| 29 |
#pragma clang diagnostic error "-Wconsumed" |
| 30 |
Linear l; |
| 31 |
return 0; // expected-error {{invalid invocation of method '~Linear' on object 'l' while it is in the 'unconsumed' state}} |
| 32 |
return 1; // expected-error {{'return' will never be executed}} |
| 33 |
#pragma clang diagnostic pop |
| 34 |
} |
| 35 |
|
| 36 |
int d() { |
| 37 |
#pragma clang diagnostic push |
| 38 |
#pragma clang diagnostic error "-Wconsumed" |
| 39 |
#pragma clang diagnostic ignored "-Wunreachable-code-aggressive" |
| 40 |
Linear l; |
| 41 |
return 0; // expected-error {{invalid invocation of method '~Linear' on object 'l' while it is in the 'unconsumed' state}} |
| 42 |
return 1; // Diagnostic is ignored |
| 43 |
} |
| 44 |
#pragma clang diagnostic pop |
| 45 |
|
| 46 |
int e() { |
| 47 |
#pragma clang diagnostic push |
| 48 |
#pragma clang diagnostic error "-Wconsumed" |
| 49 |
#pragma clang diagnostic ignored "-Wunreachable-code-aggressive" |
| 50 |
Linear l; |
| 51 |
return 0; // expected-error {{invalid invocation of method '~Linear' on object 'l' while it is in the 'unconsumed' state}} |
| 52 |
return 1; // Diagnostic is ignored |
| 53 |
#pragma clang diagnostic pop |
| 54 |
} |
| 55 |
|
| 56 |
int f() { |
| 57 |
Linear l; |
| 58 |
return 0; // No -Wconsumed diagnostic, analysis is not enabled |
| 59 |
return 1; // expected-error {{'return' will never be executed}} |
| 60 |
#pragma clang diagnostic push |
| 61 |
#pragma clang diagnostic ignored "-Wunreachable-code-aggressive" |
| 62 |
} |
| 63 |
#pragma clang diagnostic pop |
| 64 |
|
| 65 |
int g() { |
| 66 |
Linear l; |
| 67 |
return 0; // No -Wconsumed diagnostic, the diagnostic generated at } is not enabled on this line. |
| 68 |
return 1; // expected-error {{'return' will never be executed}} |
| 69 |
#pragma clang diagnostic push |
| 70 |
#pragma clang diagnostic warning "-Wconsumed" |
| 71 |
} |
| 72 |
#pragma clang diagnostic pop |
| 73 |
|
| 74 |
int h() { |
| 75 |
#pragma clang diagnostic push |
| 76 |
#pragma clang diagnostic error "-Wconsumed" |
| 77 |
#pragma clang diagnostic ignored "-Wunreachable-code-aggressive" |
| 78 |
#pragma clang diagnostic pop |
| 79 |
|
| 80 |
Linear l; |
| 81 |
return 0; // No -Wconsumed diagnostic, the diagnostic generated at } is not enabled on this line. |
| 82 |
return 1; // expected-error {{'return' will never be executed}} |
| 83 |
} |