]> granicus.if.org Git - clang/commitdiff
When parsing a character literal, extract the characters from the
authorDouglas Gregor <dgregor@apple.com>
Tue, 27 Sep 2011 17:00:18 +0000 (17:00 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 27 Sep 2011 17:00:18 +0000 (17:00 +0000)
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

lib/Lex/LiteralSupport.cpp
test/Lexer/utf8-char-literal.cpp [new file with mode: 0644]

index ef385a8aedbbd675df0888b10dbb77090f4dea1e..96550e6492bbaf78eab5d4c88d9af69cd38d158f 100644 (file)
@@ -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 (file)
index 0000000..1dbd669
--- /dev/null
@@ -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];