(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
Wformat-pr104148.c
       1  /* PR c++/104148 */
       2  /* { dg-do compile } */
       3  /* { dg-options "-Wformat" } */
       4  
       5  char *foo (const char *) __attribute__((format_arg(1)));
       6  void bar (const char *, ...) __attribute__((format(printf, 1, 2)));
       7  
       8  void
       9  baz (int x)
      10  {
      11    bar ("%ld", x);			/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      12    bar (x ? "%ld" : "%ld", x);		/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      13    bar (x ? "%ld" : "%lld", x);		/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      14  					/* { dg-warning "format '%lld' expects argument of type 'long long int', but argument 2 has type 'int'" "" { target *-*-* } .-1 } */
      15    bar (foo ("%ld"), x);			/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      16    bar (x ? foo ("%ld") : "%ld", x);	/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      17    bar (x ? foo ("%ld") : "%lld", x);	/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      18  					/* { dg-warning "format '%lld' expects argument of type 'long long int', but argument 2 has type 'int'" "" { target *-*-* } .-1 } */
      19    bar (foo (x ? "%ld" : "%ld"), x);	/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      20    bar (foo (x ? "%ld" : "%lld"), x);	/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      21  					/* { dg-warning "format '%lld' expects argument of type 'long long int', but argument 2 has type 'int'" "" { target *-*-* } .-1 } */
      22    bar (("%ld"), x);			/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      23    bar ((x ? "%ld" : "%ld"), x);		/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      24    bar ((x ? "%ld" : "%lld"), x);	/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      25  					/* { dg-warning "format '%lld' expects argument of type 'long long int', but argument 2 has type 'int'" "" { target *-*-* } .-1 } */
      26    bar ((foo ("%ld")), x);		/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      27    bar ((x ? foo ("%ld") : "%ld"), x);	/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      28    bar ((x ? foo ("%ld") : "%lld"), x);	/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      29  					/* { dg-warning "format '%lld' expects argument of type 'long long int', but argument 2 has type 'int'" "" { target *-*-* } .-1 } */
      30    bar ((foo (x ? "%ld" : "%ld")), x);	/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      31    bar ((foo (x ? "%ld" : "%lld")), x);	/* { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" } */
      32  					/* { dg-warning "format '%lld' expects argument of type 'long long int', but argument 2 has type 'int'" "" { target *-*-* } .-1 } */
      33  }