[cfe-commits] Unknown hex escapes problem
Paul Curtis
plc at rowley.co.uk
Thu Dec 2 07:07:25 PST 2010
Hi,
Given:
const char *format = "abc \m def";
clang generates:
> clang -fsyntax-only foo1.c
foo1.c(1) : warning: unknown escape sequence '\x6D'
const char *format = "abc \m def";
^
There are a couple of problems here. Firstly, the error should clearly show
\m not \x6D and ProcessCharEscape makes a valiant attempt:
if (isgraph(ThisTokBuf[0]))
Diags->Report(Loc, diag::ext_unknown_escape)
<< std::string()+(char)ResultChar;
else
Diags->Report(Loc, diag::ext_unknown_escape)
<< "x"+llvm::utohexstr(ResultChar);
Unfortunately, by the time we're in the handling case, ThisTokBuf[0] has
stepped past the invalid escape and moved to the next character, and as
witness you get a slightly different error with this source:
> clang -fsyntax-only foo1.c
foo1.c(1) : warning: unknown escape sequence '\m'
const char *format = "abc \mx def";
Now, this is correct. What ProcessCharEscape should be doing is this:
if (isgraph(ResultChar))
Diags->Report(Loc, diag::ext_unknown_escape)
<< std::string()+(char)ResultChar;
else
Diags->Report(Loc, diag::ext_unknown_escape)
<< "x"+llvm::utohexstr(ResultChar);
However the location of the caret is incorrect; perhaps I'll deal with that
next.
--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
SolderCore arriving Winter 2010! http://www.soldercore.com
More information about the cfe-commits
mailing list