https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110654
Bug ID: 110654 Summary: inconsistent error message in presence of unexpected encoded characters Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: drepper.fsp+rhbz at gmail dot com Target Milestone: --- Take this code which in a similar form was taken from a text document where the smart quote handling used the U201c and U201d characters instead of simple ASCII double quotes. Note, this text should be encoded in UTF-8 and the environment of the compiler must use UTF-8 as well. #include <stdio.h> int main() { puts(“hello world”); return 0; } Compiling this with a recent gcc 13 or older versions leads to these error messages: u.c: In function ‘main’: u.c:3:8: error: stray ‘\342’ in program 3 | puts(<U+201C>hello world<U+201D>); | ^~~~~~~~ u.c:3:9: error: ‘hello’ undeclared (first use in this function); did you mean ‘ftello’? 3 | puts(“hello world”); | ^~~~~ | ftello u.c:3:9: note: each undeclared identifier is reported only once for each function it appears in u.c:3:14: error: expected ‘)’ before ‘world’ 3 | puts(“hello world”); | ~ ^~~~~~ | ) u.c:3:20: error: stray ‘\342’ in program 3 | puts(<U+201C>hello world<U+201D>); | ^~~~~~~~ The problem is the initial message about "stray ‘\342’" and the notation used in the context line. In the later the byte is correctly recognized as being part on an UTF-8 character. Note that this is in contrast to the C++ frontend which handles this correctly. It shows: u.c:3:8: error: extended character “ is not valid in an identifier 3 | puts(“hello world”); | ^ The C frontend should adopt the same code as the C++ frontend.