#7162 Support multicharacter char literals.

This commit is contained in:
Alexander Mai 2015-11-22 13:31:31 +01:00
parent e2b859bf42
commit 9ca6704c81
2 changed files with 8 additions and 2 deletions

View File

@ -320,8 +320,13 @@ MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str)
return 0; // for unit-testing...
if (str.size()==1)
return str[0] & 0xff;
if (str[0] != '\\')
throw InternalError(0, "Internal Error. MathLib::toLongNumber: Unhandled char constant " + str);
if (str[0] != '\\') {
// C99 6.4.4.4
// The value of an integer character constant containing more than one character (e.g., 'ab'),
// or containing a character or escape sequence that does not map to a single-byte execution character,
// is implementation-defined.
return str[0] & 0xff;
}
switch (str[1]) {
case 'x':

View File

@ -271,6 +271,7 @@ private:
// from char
ASSERT_EQUALS((int)('A'), MathLib::toLongNumber("'A'"));
ASSERT_EQUALS((int)('A'), MathLib::toLongNumber("'ABC'"));
ASSERT_EQUALS((int)('\0'), MathLib::toLongNumber("'\\0'"));
ASSERT_EQUALS((int)('\r'), MathLib::toLongNumber("'\\r'"));
ASSERT_EQUALS((int)('\x12'), MathLib::toLongNumber("'\\x12'"));