brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 5d7639b Raw
62 lines · c
1// RUN: %clang_cc1 -fsyntax-only -verify=c,both -Wjump-misses-init %s2// RUN: %clang_cc1 -fsyntax-only -verify=c,both -Wc++-compat %s3// RUN: %clang_cc1 -fsyntax-only -verify=good %s4// RUN: %clang_cc1 -fsyntax-only -verify=good -fms-compatibility %s5// RUN: %clang_cc1 -fsyntax-only -verify=cxx,both -x c++ %s6// good-no-diagnostics7 8void goto_func_1(void) {9  goto ouch;  // c-warning {{jump from this goto statement to its label is incompatible with C++}} \10                 cxx-error {{cannot jump from this goto statement to its label}}11  int i = 12; // both-note {{jump bypasses variable initialization}}12 13ouch:14  ;15}16 17void goto_func_2(void) {18  goto ouch;19  static int i = 12; // This initialization is not jumped over, so no warning.20 21ouch:22  ;23}24 25void switch_func(int i) {26  switch (i) {27    int x = 12; // both-note {{jump bypasses variable initialization}}28  case 0:       // c-warning {{jump from switch statement to this case label is incompatible with C++}} \29                   cxx-error {{cannot jump from switch statement to this case label}}30    break;31  }32}33 34// Statement expressions are a bit strange in that they seem to allow for35// jumping past initialization without being diagnosed, even in C++. Perhaps36// this should change?37void f(void) {38  ({39    goto ouch;40    int i = 12;41  });42 43  for (int i = ({ goto ouch; int x = 10; x;}); i < 0; ++i) {44  }45 46ouch:47  ;48}49 50void indirect(int n) {51DirectJump:52  ;53 54  void *Table[] = {&&DirectJump, &&Later};55  goto *Table[n]; // c-warning {{jump from this indirect goto statement to one of its possible targets is incompatible with C++}} \56                     cxx-error {{cannot jump from this indirect goto statement to one of its possible targets}}57 58  int x = 12;     // both-note {{jump bypasses variable initialization}}59Later:            // both-note {{possible target of indirect goto statement}}60  ;61}62