view gcc/testsuite/c-c++-common/Wint-in-bool-context.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++/77434 */
/* { dg-options "-Wint-in-bool-context" } */
/* { dg-do compile } */

enum truth { yes, no, maybe };

int foo (int a, int b)
{
  if (a > 0 && a <= (b == 1) ? 1 : 2) /* { dg-warning "boolean context" } */
    return 1;

  if (a > 0 && a <= (b == 2) ? 1 : 1) /* { dg-bogus "boolean context" } */
    return 2;

  if (a > 0 && a <= (b == 3) ? 0 : 2) /* { dg-warning "boolean context" } */
    return 3;

  if (a == b ? 0 : 0) /* { dg-bogus "boolean context" } */
    return 4;

  if (a == ((b ? 2|4 : 1) & 3 ? 0 : 2)) /* { dg-bogus "boolean context" } */
    return 5;

  if (a ? 1 : 1+1) /* { dg-warning "boolean context" } */
    return 6;

  if (b ? 1+1 : 1) /* { dg-warning "boolean context" } */
    return 7;

  for (a = 0; 1 << a; a++); /* { dg-warning "boolean context" } */

  if (yes || no || maybe) /* { dg-warning "boolean context" "" { target c++ } } */
    return 8;

  if (yes || no) /* { dg-bogus "boolean context" } */
    return 9;

  return 0;
}