diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-09-27 17:00:18 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-09-27 17:00:18 +0000 |
commit | 17c8c84fbc5cbde336fdef8fffe63c08a955ade9 (patch) | |
tree | e29df19b73c24b682fd2dc139ed22f0041b07f18 | |
parent | c737acb8e86564becc5939d681089d1851e6be1a (diff) |
When parsing a character literal, extract the characters from the
buffer as an 'unsigned char', so that integer promotion doesn't
sign-extend character values > 127 into oblivion. Fixes
<rdar://problem/10188919>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140608 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Lex/LiteralSupport.cpp | 2 | ||||
-rw-r--r-- | test/Lexer/utf8-char-literal.cpp | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp index ef385a8aed..96550e6492 100644 --- a/lib/Lex/LiteralSupport.cpp +++ b/lib/Lex/LiteralSupport.cpp @@ -784,7 +784,7 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end, // Is this a Universal Character Name escape? if (begin[0] != '\\') // If this is a normal character, consume it. - ResultChar = *begin++; + ResultChar = (unsigned char)*begin++; else { // Otherwise, this is an escape character. unsigned CharWidth = getCharWidth(Kind, PP.getTargetInfo()); // Check for UCN. diff --git a/test/Lexer/utf8-char-literal.cpp b/test/Lexer/utf8-char-literal.cpp new file mode 100644 index 0000000000..1dbd669cfd --- /dev/null +++ b/test/Lexer/utf8-char-literal.cpp @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++0x -fsyntax-only -verify %s + +int array0[u'ñ' == u'\xf1'? 1 : -1]; +int array1['ñ' != u'\xf1'? 1 : -1]; |