view gcc/testsuite/c-c++-common/Wmultistatement-macros-1.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/80116 */
/* { dg-options "-Wmultistatement-macros" } */
/* { dg-do compile } */

#define SWAP(X, Y)	\
  tmp = X; /* { dg-warning "macro expands to multiple statements" } */ \
  X = Y;		\
  Y = tmp

#define STUFF		\
  if (0) x = y

#define STUFF2		\
  if (0) x = y; x++

#define STUFF3		\
  if (x) /* { dg-message "not guarded by this 'if' clause" } */ \
    SWAP(x, y) /* { dg-message "in expansion of macro .SWAP." } */

#define SET(X, Y)	\
  (X) = (Y)

#define STUFF4		\
  if (x)		\
    SET(x, y);		\
  SET(x, y)

#define STUFF5		\
  { tmp = x; x = y; }

#define STUFF6		\
  x++;;

int x, y, tmp;

void
fn1 (void)
{
  if (x) /* { dg-message "not guarded by this 'if' clause" } */
    SWAP(x, y); /* { dg-message "in expansion of macro .SWAP." } */
}

void
fn2 (void)
{
  SWAP(x, y);
}

void
fn3 (void)
{
  if (x)
    {
      SWAP(x, y);
    }
}

void
fn4 (void)
{
  if (x)
  ({ x = 10; x++; });
}

void
fn5 (void)
{
  if (x) /* { dg-message "not guarded by this 'if' clause" } */
L1:
    SWAP (x, y); /* { dg-message "in expansion of macro .SWAP." } */
  goto L1;
}

void
fn6 (void)
{
  if (x)
    SET (x, y);
  SET (tmp, x);
}

void
fn7 (void)
{
  STUFF;
}

void
fn8 (void)
{
  STUFF2;
}

void
fn9 (void)
{
  STUFF3; /* { dg-message "in expansion of macro .STUFF3." } */
}

void
fn10 (void)
{
  STUFF4;
}

void
fn11 (void)
{
  if (x)
    STUFF5;
}

void
fn12 (void)
{
  if (x)
    STUFF6;
}