c-common.c (check_format_info): Warn for a wide character string used as a non-wide format argument.

* c-common.c (check_format_info): Warn for a wide character string
	used as a non-wide format argument.

testsuite:
	* gcc.dg/c90-printf-1.c: Add test for wide string format.

From-SVN: r36586
This commit is contained in:
Joseph Myers 2000-09-24 10:52:53 +01:00 committed by Joseph Myers
parent 1c44c45dbf
commit c5412f0646
4 changed files with 15 additions and 0 deletions

View File

@ -1,3 +1,8 @@
2000-09-24 Joseph S. Myers <jsm28@cam.ac.uk>
* c-common.c (check_format_info): Warn for a wide character string
used as a non-wide format argument.
2000-09-24 Joseph S. Myers <jsm28@cam.ac.uk> 2000-09-24 Joseph S. Myers <jsm28@cam.ac.uk>
* builtins.def (BUILT_IN_LLABS): Add. * builtins.def (BUILT_IN_LLABS): Add.

View File

@ -2040,6 +2040,11 @@ check_format_info (status, info, params)
status_warning (status, "format not a string literal, argument types not checked"); status_warning (status, "format not a string literal, argument types not checked");
return; return;
} }
if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (format_tree))) != char_type_node)
{
status_warning (status, "format is a wide character string");
return;
}
format_chars = TREE_STRING_POINTER (format_tree); format_chars = TREE_STRING_POINTER (format_tree);
format_length = TREE_STRING_LENGTH (format_tree); format_length = TREE_STRING_LENGTH (format_tree);
if (format_length <= 1) if (format_length <= 1)

View File

@ -1,3 +1,7 @@
2000-09-24 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.dg/c90-printf-1.c: Add test for wide string format.
2000-09-22 Geoff Keating <geoffk@cygnus.com> 2000-09-22 Geoff Keating <geoffk@cygnus.com>
* gcc.c-torture/compile/20000922-1.c: New file. * gcc.c-torture/compile/20000922-1.c: New file.

View File

@ -243,5 +243,6 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p,
printf ("%"); /* { dg-warning "trailing" "trailing % warning" } */ printf ("%"); /* { dg-warning "trailing" "trailing % warning" } */
printf ("%++d", i); /* { dg-warning "repeated" "repeated flag warning" } */ printf ("%++d", i); /* { dg-warning "repeated" "repeated flag warning" } */
printf ("%n", cn); /* { dg-warning "constant" "%n with const" } */ printf ("%n", cn); /* { dg-warning "constant" "%n with const" } */
printf ((const char *)L"foo"); /* { dg-warning "wide" "wide string" } */
/* Can we test for the warning for unterminated string formats? */ /* Can we test for the warning for unterminated string formats? */
} }