Commit 6d2e1454 by Joseph Myers Committed by Joseph Myers

c-common.c (format_check_results): New structure.

	* c-common.c (format_check_results): New structure.
	(finish_dollar_format_checking): Adjust to take a
	format_check_results * parameter.
	(check_format_info, check_format_info_recurse,
	check_format_info_main): Split check_format_info into three
	functions, the main checking going in check_format_info_main.
	Recurse when any reduction of the format string argument towards a
	string literal is done; go down both branches of a conditional
	expression.  Don't warn for extra format arguments or empty format
	strings if they only occur in some branches of a conditional
	expression.

testsuite:
	* gcc.dg/format-branch-1.c: New test.

From-SVN: r36883
parent 406df25c
2000-10-16 Joseph S. Myers <jsm28@cam.ac.uk>
* c-common.c (format_check_results): New structure.
(finish_dollar_format_checking): Adjust to take a
format_check_results * parameter.
(check_format_info, check_format_info_recurse,
check_format_info_main): Split check_format_info into three
functions, the main checking going in check_format_info_main.
Recurse when any reduction of the format string argument towards a
string literal is done; go down both branches of a conditional
expression. Don't warn for extra format arguments or empty format
strings if they only occur in some branches of a conditional
expression.
2000-10-16 Kazu Hirata <kazu@hxi.com> 2000-10-16 Kazu Hirata <kazu@hxi.com>
* config/h8300/h8300.c: Remove obstack. * config/h8300/h8300.c: Remove obstack.
......
2000-10-16 Joseph S. Myers <jsm28@cam.ac.uk> 2000-10-16 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.dg/format-branch-1.c: New test.
2000-10-16 Joseph S. Myers <jsm28@cam.ac.uk>
* README, lib/file-format.exp: Remove EGCS references. * README, lib/file-format.exp: Remove EGCS references.
2000-10-16 Jakub Jelinek <jakub@redhat.com> 2000-10-16 Jakub Jelinek <jakub@redhat.com>
......
/* Test for format checking of conditional expressions. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wformat" } */
#define NULL ((void *)0)
extern int printf (const char *, ...);
void
foo (long l, int nfoo)
{
printf ((nfoo > 1) ? "%d foos" : "%d foo", nfoo);
printf ((l > 1) ? "%d foos" : "%d foo", l); /* { dg-warning "int format" "wrong type in conditional expr" } */
printf ((l > 1) ? "%ld foos" : "%d foo", l); /* { dg-warning "int format" "wrong type in conditional expr" } */
printf ((l > 1) ? "%d foos" : "%ld foo", l); /* { dg-warning "int format" "wrong type in conditional expr" } */
/* Should allow one case to have extra arguments. */
printf ((nfoo > 1) ? "%d foos" : "1 foo", nfoo);
printf ((nfoo > 1) ? "many foos" : "1 foo", nfoo); /* { dg-warning "too many" "too many args in all branches" } */
printf ((nfoo > 1) ? "%d foos" : "", nfoo);
printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "1 foo" : "no foos"), nfoo);
printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo);
printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%ld foos"), nfoo); /* { dg-warning "long int format" "wrong type" } */
printf ((nfoo > 1) ? "%ld foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo); /* { dg-warning "long int format" "wrong type" } */
printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%ld foo" : "%d foos"), nfoo); /* { dg-warning "long int format" "wrong type" } */
/* Extra arguments to NULL should be complained about. */
printf (NULL, "foo"); /* { dg-warning "too many" "NULL extra args" } */
/* { dg-warning "null" "null format arg" { target *-*-* } 27 } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment