public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110654] New: inconsistent error message in presence of unexpected encoded characters
@ 2023-07-13 10:12 drepper.fsp+rhbz at gmail dot com
2023-07-13 15:41 ` [Bug c/110654] " pinskia at gcc dot gnu.org
2023-07-14 18:29 ` drepper.fsp+rhbz at gmail dot com
0 siblings, 2 replies; 3+ messages in thread
From: drepper.fsp+rhbz at gmail dot com @ 2023-07-13 10:12 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/110654] inconsistent error message in presence of unexpected encoded characters
2023-07-13 10:12 [Bug c/110654] New: inconsistent error message in presence of unexpected encoded characters drepper.fsp+rhbz at gmail dot com
@ 2023-07-13 15:41 ` pinskia at gcc dot gnu.org
2023-07-14 18:29 ` drepper.fsp+rhbz at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-13 15:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110654
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
libccp has:
/* In C++, this is an error for invalid character in an identifier
because logically, the UTF-8 was converted to a UCN during
translation phase 1 (even though we don't physically do it that
way). In C, this byte rather becomes grammatically a separate
token. */
if (CPP_OPTION (pfile, cplusplus))
cpp_error (pfile, CPP_DL_ERROR,
"extended character %.*s is not valid in an identifier",
(int) (*pstr - base), base);
else
{
*pstr = base;
return false;
}
So this is due to differences in the languages themselves rather than due to C
vs C++ front-end ...
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/110654] inconsistent error message in presence of unexpected encoded characters
2023-07-13 10:12 [Bug c/110654] New: inconsistent error message in presence of unexpected encoded characters drepper.fsp+rhbz at gmail dot com
2023-07-13 15:41 ` [Bug c/110654] " pinskia at gcc dot gnu.org
@ 2023-07-14 18:29 ` drepper.fsp+rhbz at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: drepper.fsp+rhbz at gmail dot com @ 2023-07-14 18:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110654
--- Comment #2 from Ulrich Drepper <drepper.fsp+rhbz at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> So this is due to differences in the languages themselves rather than due to
> C vs C++ front-end ...
This is certainly true for the validation.
But the standard never says anything about how an error should be reported. I
don't think there is a reason to make this more obscure than necessary.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-14 18:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-13 10:12 [Bug c/110654] New: inconsistent error message in presence of unexpected encoded characters drepper.fsp+rhbz at gmail dot com
2023-07-13 15:41 ` [Bug c/110654] " pinskia at gcc dot gnu.org
2023-07-14 18:29 ` drepper.fsp+rhbz at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).