view gcc/testsuite/g++.dg/cpp0x/fallthrough1.C @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
line wrap: on
line source

// PR c/7652
// { dg-do compile { target c++11 } }
// { dg-options "-Wextra -Wall -Wpedantic" }

extern void bar (int);
void
fn (int i)
{
  [[gnu::fallthrough]] int j = 0; // { dg-warning "attribute ignored" }

  if (j)
    [[gnu::fallthrough]];  // { dg-error "invalid use" }

  [[gnu::fallthrough]];  // { dg-error "invalid use" }
  switch (i)
  {
    [[gnu::fallthrough]]; // { dg-warning "statement will never" }
  case 1:
   i++;
   [[gnu::fallthrough]];
  case 2:
    if (i) // { dg-warning "statement may fall through" }
      bar (2);
    else
      [[gnu::fallthrough]];
  case 3:
    if (i > 1)
      [[gnu::fallthrough]];
    else
      return;
  case 4:
    if (i)
      [[gnu::fallthrough]]; // { dg-warning "not preceding" }
    [[gnu::fallthrough]];
  case 5:
   ;
   [[gnu::fallthrough]];
  case 6:
    if (i) // { dg-warning "statement may fall through" }
      bar (6);
    else
      {
	[[gnu::fallthrough]];
      }
  case 7:
    if (i > 1)
      {
	[[gnu::fallthrough]];
      }
    else
      bar (7); // { dg-warning "statement may fall through" }
  default:
    --j;
  }

  [[gnu::fallthrough]]; // { dg-error "invalid use" }
}