Bug 38308 - -Wformat does not work for wide strings
Summary: -Wformat does not work for wide strings
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 53612 93406 (view as bug list)
Depends on:
Blocks: 64862 33748
  Show dependency treegraph
 
Reported: 2008-11-28 16:37 UTC by Paolo Bonzini
Modified: 2024-04-08 21:05 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-11-29 03:12:35


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paolo Bonzini 2008-11-28 16:37:32 UTC
GCC does not warn for this:

int main()
{
  wprintf (L"%s", 5);
}

GCC should try converting the string to single-byte (e.g. to UTF-8, which would work for any wchar_t encoding in which 0-127 maps to char's encoding) and test the format string.
Comment 1 Andrew Pinski 2008-11-28 16:58:38 UTC
A patch was posted a while back:
http://gcc.gnu.org/ml/gcc-patches/2001-12/msg01579.html
Comment 2 jsm-csl@polyomino.org.uk 2008-11-28 17:26:01 UTC
Subject: Re:  -Wformat does not work for wide strings

In view of the removal of c4x support I don't now think any patch for this 
needs to address the format of STRING_CSTs for non-8-bit target bytes.  
But it should still have appropriate accessors for extracting bytes / 
multibyte characters / wide characters from strings (such that support for 
non-8-bit target bytes could be added to those accessors later), though 
without necessarily finding all existing code that should be using those 
accessors.

See also bug 20110 on the format checking not allowing for the execution 
character set once it's extracted a character from the string.  For wide 
characters it's -fwide-exec-charset that's relevant.

Comment 3 Andrew Pinski 2008-11-29 03:12:35 UTC
Confirmed.
Comment 4 Andrew Pinski 2012-06-08 18:42:45 UTC
*** Bug 53612 has been marked as a duplicate of this bug. ***
Comment 5 Joseph S. Myers 2020-01-23 20:36:18 UTC
*** Bug 93406 has been marked as a duplicate of this bug. ***
Comment 6 Joseph S. Myers 2020-01-24 21:51:28 UTC
*** Bug 93406 has been marked as a duplicate of this bug. ***
Comment 7 jerome.hamm 2020-01-25 10:45:00 UTC
I know nothing of the inner workings of gcc, but what I can imagine, is that to check a wchar_t string is easier than a char string, because some encodings may use variable length multibyte encodings that might, when looked as individual bytes, overlap the ASCII alphabet character encoding (UTF-8 does not, but I suspect others might), but wchar_t should not, i.e. 'd' can only be equal to L'd'. So I don't see why checking for wchar_t is not done (but I must miss a big point).