[cfe-commits] [PATCH] Warn and truncate UCNs that are too large in narrow character literals

Craig Topper craig.topper at gmail.com
Sun Aug 14 23:46:23 PDT 2011


UCNs larger than 8-bits in narrow character literals are currently
allowed to silently cause weird behavior. They don't set the multichar
flag so the lower 8-bits can be sign extended over the upper bits of
the UCN. If another character follows the UCN, the upper byte of the
UCN and the next character are silently added together.

Short wchar_t and char16_t do throw a warning for overflow, but the
data isn't truncated.

This patch adds a warning for the 8-bit cases and truncates the data
to prevent corrupting neighboring bytes.

This behavior differs from gcc which converts the UCNs to UTF-16 or
UTF-8 as appropriate and calls them multicharacter. I can pursue
matching gcc if that's what we desire, but for now I took the simpler
approach.

-- 
~Craig
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ucn_warn.patch
Type: application/octet-stream
Size: 2080 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110814/0bb478f1/attachment.obj>


More information about the cfe-commits mailing list