brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 7d2f25e Raw
84 lines · c
1// RUN: %clang_cc1 -fsyntax-only -std=c23 -verify %s2 3// This is the latest version of fallthrough that we support.4_Static_assert(__has_c_attribute(fallthrough) == 201910L);5 6void f(int n) {7  switch (n) {8  case 0:9    n += 1;10    [[fallthrough]]; // ok11  case 1:12    if (n) {13      [[fallthrough]]; // ok14    } else {15      return;16    }17  case 2:18    for (int n = 0; n != 10; ++n)19      [[fallthrough]]; // expected-error {{does not directly precede switch label}} \20                       // expected-warning {{ISO C does not allow an attribute list to appear here}}21  case 3:22    while (1)23      [[fallthrough]]; // expected-error {{does not directly precede switch label}} \24      // expected-warning {{ISO C does not allow an attribute list to appear here}}25  case 4:26    while (0)27      [[fallthrough]]; // expected-error {{does not directly precede switch label}} \28      // expected-warning {{ISO C does not allow an attribute list to appear here}}29  case 5:30    do [[fallthrough]]; while (1); // expected-error {{does not directly precede switch label}} \31    // expected-warning {{ISO C does not allow an attribute list to appear here}}32  case 6:33    do [[fallthrough]]; while (0); // expected-error {{does not directly precede switch label}} \34    // expected-warning {{ISO C does not allow an attribute list to appear here}}35  case 7:36    switch (n) {37    case 0:38      // FIXME: This should be an error, even though the next thing we do is to39      // fall through in an outer switch statement.40      [[fallthrough]];41    }42  case 8:43    [[fallthrough]]; // expected-error {{does not directly precede switch label}}44    goto label;45  label:46  case 9:47    n += 1;48  case 10: // no warning, -Wimplicit-fallthrough is not enabled in this test, and does not need to49           // be enabled for these diagnostics to be produced.50    break;51  }52}53 54[[fallthrough]] typedef int n1; // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}55typedef int [[fallthrough]] n2; // expected-error {{'fallthrough' attribute cannot be applied to types}}56typedef int n3 [[fallthrough]]; // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}57 58enum [[fallthrough]] E { // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}59  One60};61struct [[fallthrough]] S { // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}62  int i;63};64 65[[fallthrough]] // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}66void g(void) {67  [[fallthrough]] int n; // expected-error {{'fallthrough' attribute cannot be applied to a declaration}}68  [[fallthrough]] ++n; // expected-error {{'fallthrough' attribute only applies to empty statements}}69 70  switch (n) {71    // FIXME: This should be an error.72    [[fallthrough]];73    return;74 75  case 0:76    [[fallthrough, fallthrough]]; // ok77  case 1:78    [[fallthrough(0)]]; // expected-error {{argument list}}79  case 2:80    break;81  }82}83 84