On 02/07/2018 06:53 PM, David Malcolm wrote: > PR c/84258 reports that we issue this: > > warning: format is a wide character string [-Wformat=] > > on this code: > > const unsigned char cuc[] = "%i"; > sprintf(buf, (char *)cuc, 1); > > despite the absence of wide characters. > > This wording dates back 17.5 years to r36586: > > 2000-09-24 Joseph S. Myers <js...@cam.ac.uk> > > * c-common.c (check_format_info): Warn for a wide character string > used as a non-wide format argument. > > * gcc.dg/c90-printf-1.c: Add test for wide string format. > > which handled this case: > > printf ((const char *)L"foo"); /* { dg-warning "wide" "wide string" } */ > > The code in question is currently just checking for something that isn't > char_type_node. > > digest_init converts the string literal to the type of the array, converting > it from array of char to array of unsigned char, leading to the condition > failing. > > This patch fixes the nonsensical message by checking for the other string > types that lex_string can emit - char16_array_type_node, > char32_array_type_node, and wchar_array_type_node - and only referring > to "wide character string" if it's one of them. Otherwise it uses a new, > more generic wording. > > Successfully bootstrapped®rtested on x86_64-pc-linux-gnu. > > This isn't a regression, but is fairly low risk. > > OK for trunk, either now, or for next stage 1? > > gcc/c-family/ChangeLog: > PR c/84258 > * c-format.c (struct format_check_results): Add field > "number_non_char". > (check_format_info): Initialize it, and warn if encountered. > (check_format_arg): Distinguish between wide char and > everything else when detecting arrays of non-char. > > gcc/testsuite/ChangeLog: > PR c/84258 > * c-c++-common/Wformat-pr84258.c: New test. OK for the trunk.
Jeff