brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 470960c Raw
84 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -Werror=unreachable-code-aggressive %s2 3// Test that analysis-based warnings honor #pragma diagnostic controls.4 5struct [[clang::consumable(unconsumed)]] Linear {6  [[clang::return_typestate(unconsumed)]]7  Linear() {}8  [[clang::callable_when(consumed)]]9  ~Linear() {}10};11 12int 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 push19#pragma clang diagnostic error "-Wconsumed"20int 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 pop26 27int c() {28#pragma clang diagnostic push29#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 pop34}35 36int d() {37#pragma clang diagnostic push38#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 ignored43}44#pragma clang diagnostic pop45 46int e() {47#pragma clang diagnostic push48#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 ignored53#pragma clang diagnostic pop54}55 56int f() {57  Linear l;58  return 0; // No -Wconsumed diagnostic, analysis is not enabled59  return 1; // expected-error {{'return' will never be executed}}60#pragma clang diagnostic push61#pragma clang diagnostic ignored "-Wunreachable-code-aggressive"62}63#pragma clang diagnostic pop	64 65int 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 push70#pragma clang diagnostic warning "-Wconsumed"71}72#pragma clang diagnostic pop73 74int h() {75#pragma clang diagnostic push76#pragma clang diagnostic error "-Wconsumed"77#pragma clang diagnostic ignored "-Wunreachable-code-aggressive"78#pragma clang diagnostic pop79 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}84