Warning for trigraphs in comment?
Gabriel Dos Reis
gdr@integrable-solutions.net
Sun May 18 13:37:00 GMT 2003
This
<quote>
Second, consider the comment line. Did you notice that it ends oddly,
with a "/"?
// What will the next line do? Increment???????????/
^
Nikolai Smirnov writes:
"Probably, what's happened in the program is obvious for you but I
lost a couple of days debugging a big program where I made a
similar error. I put a comment line ending with a lot of question
marks accidentally releasing the 'Shift' key at the end. The
result is unexpected trigraph sequence '??/' which was converted to
'\' (phase 1) which was annihilated with the following '\n' (phase
2)." [1]
The "??/" sequence is converted to '\' which, at the end of a line, is
a line-splicing directive (surprise!). In this case, it splices the
following line "++x;" to the end of the comment line and thus makes
the increment part of the comment. The increment is never executed.
Interestingly, if you look at the Gnu g++ documentation for the
-Wtrigraphs command-line switch, you will encounter the following
statement:
"Warnings are not given for trigraphs within comments, as they do
not affect the meaning of the program." [2]
That may be true most of the time, but here we have a case in point --
from real-world code, no less -- where this expectation does not hold.
</quote>
is extracted from Herb's GTW #86 -- full message appended below.
I would suggest we warn for trigraphs in comments.
-- Gaby
-------------- next part --------------
An embedded message was scrubbed...
From: Herb Sutter <hsutter@gotw.ca>
Subject: Guru of the Week #86: Solution
Date: 17 May 2003 17:04:31 -0400
Size: 6445
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20030518/784be26e/attachment.eml>
-------------- next part --------------
--
Gabriel Dos Reis, gdr@integrable-solutions.net
More information about the Gcc
mailing list