Use clang/gcc-conforming encoding of multicharacter literals

This commit is contained in:
Alexander Mai 2015-11-22 14:20:36 +01:00
parent f516de8633
commit 63b7700660
2 changed files with 12 additions and 2 deletions

View File

@ -325,7 +325,12 @@ MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str)
// 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;
// clang and gcc seem to use the following encoding: 'AB' as (('A' << 8) | 'B')
int retval(str.front());
for (std::string::const_iterator it=str.begin()+1; it!=str.end(); ++it) {
retval = retval<<8 | *it;
}
return retval; // str[0] & 0xff;
}
switch (str[1]) {

View File

@ -271,7 +271,12 @@ private:
// from char
ASSERT_EQUALS((int)('A'), MathLib::toLongNumber("'A'"));
ASSERT_EQUALS((int)('A'), MathLib::toLongNumber("'ABC'"));
// BEGIN Implementation-specific results
ASSERT_EQUALS((int)('AB'), MathLib::toLongNumber("'AB'"));
ASSERT_EQUALS((int)('ABC'), MathLib::toLongNumber("'ABC'"));
ASSERT_EQUALS((int)('ABCD'), MathLib::toLongNumber("'ABCD'"));
ASSERT_EQUALS((int)('ABCDE'), MathLib::toLongNumber("'ABCDE'"));
// END Implementation-specific results
ASSERT_EQUALS((int)('\0'), MathLib::toLongNumber("'\\0'"));
ASSERT_EQUALS((int)('\r'), MathLib::toLongNumber("'\\r'"));
ASSERT_EQUALS((int)('\x12'), MathLib::toLongNumber("'\\x12'"));