Hi, all,<br><br>I wrote a patch to implement new char16_t and char32_t character literals introduced in C++0x.<br>My implementation is based on 2.13.3 Character literals [lex.ccon], C++0x draft N3242.<br>Could you review my patch and feed me back your comments and requests?<br>


<br>* New features<br><br>Compiling sources with -std=c++0x option, clang accepts the char16_t and char32_t character<br>literals.<br><br>At this point, there is a limitation. See also (1) in the TODO list below.<br><br>

* Source Example<br>
<br>char16_t a = u'a';   // u'a'  has char16_t type. The value is \u0061 in UTF16.<br>char32_t b = U'b';  // U'b'  has char32_t type, The value  is \U00000062 in UTF32.<br><br><br>* Implementation<br>


<br>I added 3 token kinds, tok::wchar_constnat, tok::utf16char_constant, tok::utf32char_constant.<br>( include/clang/Basic/TokenKinds.def)<br><br>If the Lexer finds the token starting with L', u' or U' , it try to construct a char literal token<br>


whose token kinds are tok::wchar_constant, tok::utf16char_constant, or  tok::utf32char_constant.<br>(Lexer::LexTokenInternal(Token& Result),  lib/Lex/Lexer.cpp)<br><br>To make it easy to set the proper token kind to the char literal token object, I modified the class<br>


CharLiteralParser so that it has a private member to hold a token kind, and append an argument<br>to the ctor to take the literal kind. <br>(include/clang/Lex/LiteralSupport.h, lib/Lex/LiteralSupport.h)<br><br>The parser and Sema set appropriate type for wchar_t, char16_t and char32_t literal.<br>


(Parser:::ParseCastExpression,  lib/Parse/ParseExpr.cpp<br><br><br>* TODO<br><br>(1) No Code Conversion.<br>At this point, only ascii characters are available in the char16_t and char32_t constants because <br>
I have not implemented code conversion logic. I plan to fix the problem in next patch to support<br>chart16_t and char32_t string literals.<br><br>(2) Code Gen Problem.<br>When defining an array whose type of char32_t (4byte aligned type), the array is aligned to 16 byte<br>


boundary instead of 4byte. I think this is a bug in clang. A test program in my patch, <br>test/CodeGenCXX/cxx0x-char-literal.cpp, line 33 and 34, demonstrates the problem.<br><br><br>* Test Environment and Result <br>My patch based on r131788.<br>


And I checked it on Fedora14 x86_64.<br><br>There is no degradation.<br>But a problems is found as described in TODO list.<br><br>-----<br>Yusaku Shiga<br><br>