comparison gcc/testsuite/gcc.dg/format/ms_branch-1.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* Test for format checking of conditional expressions. */
2 /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
3 /* { dg-do compile { target { *-*-mingw* } } } */
4 /* { dg-options "-std=gnu99 -Wformat" } */
5
6 #define USE_SYSTEM_FORMATS
7 #include "format.h"
8
9 void
10 foo (long l, int nfoo)
11 {
12 printf ((nfoo > 1) ? "%d foos" : "%d foo", nfoo);
13 printf ((l > 1) ? "%d foos" : "%d foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */
14 printf ((l > 1) ? "%ld foos" : "%d foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */
15 printf ((l > 1) ? "%d foos" : "%ld foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */
16 /* Should allow one case to have extra arguments. */
17 printf ((nfoo > 1) ? "%d foos" : "1 foo", nfoo);
18 printf ((nfoo > 1) ? "many foos" : "1 foo", nfoo); /* { dg-warning "too many" "too many args in all branches" } */
19 printf ((nfoo > 1) ? "%d foos" : "", nfoo);
20 printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "1 foo" : "no foos"), nfoo);
21 printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo);
22 printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%ld foos"), nfoo); /* { dg-warning "long int" "wrong type" } */
23 printf ((nfoo > 1) ? "%ld foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo); /* { dg-warning "long int" "wrong type" } */
24 printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%ld foo" : "%d foos"), nfoo); /* { dg-warning "long int" "wrong type" } */
25 /* Extra arguments to NULL should be complained about. */
26 printf (NULL, "foo"); /* { dg-warning "too many" "NULL extra args" } */
27 /* { dg-warning "null" "null format arg" { target *-*-* } .-1 } */
28 }