optimization/4130: gcc 3.0 -O2 and printf optimization

Richard Henderson rth@redhat.com
Wed Apr 3 10:41:00 GMT 2002


----- Forwarded message from Ulrich Drepper <drepper@redhat.com> -----

> My copy of the draft standard says:
> 
>     An encoding error occurs if the character sequence presented to
>     the underlying mbrtowc function does not form a valid
>     (generalized) multibyte character, or if the code value passed to
>     the underlying wcrtomb does not correspond to a valid
>     (generalized) multibyte character. The wide-character input/output
>     functions and the byte input/output functions store the value of
>     the macro EILSEQ in errno if and only if an encoding error occurs.
> 
> And:
> 
>     The printf function returns the number of characters transmitted,
>     or a negative value if an output or encoding error occurred.

This has nothing to do with the problem.  It applies to the strings
which are passed in for "%s" etc.  The fprintf() definition says that
the format string is a multibyte character string.  If this is violated
(e.g., if there is an invalid character) the result in unspecified.

Any format string (and the arguments to puts, fputs, etc) have to be
scrutinized by the compiler.  The compiler has to know what encoding the
file uses.  If it finds an invalid multibyte character it must report
this.  If the compilation succeeds the result can be expected to be
valid.

Now one can argue that gcc should actually do these tests (what is not
the case) but it's unrelated to the problem at hand.

----- End forwarded message -----



More information about the Gcc-bugs mailing list