views:

29

answers:

1

I recently decided to switch to clang from gcc and I’m getting the following warning for my use of wide character constants: "extraneous characters in wide character constant ignored". Here is the code that gets the warning:

wstring& line;
…
for (wstring::iterator ch = line.begin(); ch != line.end(); ++ch)
    switch (*ch) {
        case L'│': *ch = L'|'; break;
        case L'﹤': *ch = L'<'; break;
        case L'﹥': *ch = L'>'; break;
        case L'﹙': *ch = L'('; break;
        case L'﹚': *ch = L')'; break;
        default: break;
    }

Here, the characters in the case conditions are all high-unicode characters and therefore seen as multibyte characters by the clang parser, apparently (the source code is UTF-8 encoded).

My question is what is the meaning behind the warning message. That is, what exactly is being ignored. Also, given this warning, will my program work as designed?

gcc does not give any warnings for this code and everything works like a charm.

A: 

At the heart of the program is the interpretation of the source file. You know that it's UTF-8 encoded. That's why the 6 bytes L'﹤' are to be interpreted as 4 Unicode characters. But how would clang know? It sees 6 bytes, and assumes an 8 bit encoding. Thus, it sees L'xyz' (the precise characters depend on the assumed 8 bit character set). clang tells you that it is interpreting L'xyz' as L'x' , ignoring y and z. It's extremely unlikely that works as intended.

MSalters
Hmm gcc never had any problem here. Is there a way to tell clang to properly handle UTF-8 source files, or alternatively to input the wide characters so that clang understands them?
Ventzi Zhechev
http://github.com/bratsche/clang suggests not: IV. Missing Functionality / ImprovementsLexer: * Source character mapping. GCC supports ASCII and UTF-8.
MSalters