diff options
author | Neil Booth <neil@daikokuya.demon.co.uk> | 2002-02-24 12:52:30 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2002-02-24 12:52:30 +0000 |
commit | a47ed31052e27000eb57521bb4c9e600a4768a98 (patch) | |
tree | b8bc66887f2c3523f7edef448ecb1be8ff9d481a /gcc/cpplex.c | |
parent | cb8f73be28c7ad42f8244cc9e442c7559d39f725 (diff) | |
download | gcc-a47ed31052e27000eb57521bb4c9e600a4768a98.zip gcc-a47ed31052e27000eb57521bb4c9e600a4768a98.tar.gz gcc-a47ed31052e27000eb57521bb4c9e600a4768a98.tar.bz2 |
cpplex.c (cpp_interpret_charconst): Get signedness or otherwise of wide character constants correct.
* cpplex.c (cpp_interpret_charconst): Get signedness or
otherwise of wide character constants correct.
* cppexp.c (lex): Get signedness of wide charconsts correct.
* testsuite/gcc.dg/cpp/wchar-1.c: New test.
From-SVN: r50005
Diffstat (limited to 'gcc/cpplex.c')
-rw-r--r-- | gcc/cpplex.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/gcc/cpplex.c b/gcc/cpplex.c index 70e6280..eea6a9e 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -1837,6 +1837,7 @@ cpp_interpret_charconst (pfile, token, warn_multi, traditional, pchars_seen) unsigned int width, max_chars, c; unsigned HOST_WIDE_INT mask; HOST_WIDE_INT result = 0; + bool unsigned_p; #ifdef MULTIBYTE_CHARS (void) local_mbtowc (NULL, NULL, 0); @@ -1844,9 +1845,15 @@ cpp_interpret_charconst (pfile, token, warn_multi, traditional, pchars_seen) /* Width in bits. */ if (token->type == CPP_CHAR) - width = MAX_CHAR_TYPE_SIZE; + { + width = MAX_CHAR_TYPE_SIZE; + unsigned_p = CPP_OPTION (pfile, signed_char) == 0; + } else - width = MAX_WCHAR_TYPE_SIZE; + { + width = MAX_WCHAR_TYPE_SIZE; + unsigned_p = WCHAR_UNSIGNED; + } if (width < HOST_BITS_PER_WIDE_INT) mask = ((unsigned HOST_WIDE_INT) 1 << width) - 1; @@ -1903,14 +1910,13 @@ cpp_interpret_charconst (pfile, token, warn_multi, traditional, pchars_seen) else if (chars_seen > 1 && !traditional && warn_multi) cpp_warning (pfile, "multi-character character constant"); - /* If char type is signed, sign-extend the constant. */ - if (token->type == CPP_CHAR && chars_seen) + /* If relevant type is signed, sign-extend the constant. */ + if (chars_seen) { unsigned int nbits = chars_seen * width; mask = (unsigned HOST_WIDE_INT) ~0 >> (HOST_BITS_PER_WIDE_INT - nbits); - if (CPP_OPTION (pfile, signed_char) == 0 - || ((result >> (nbits - 1)) & 1) == 0) + if (unsigned_p || ((result >> (nbits - 1)) & 1) == 0) result &= mask; else result |= ~mask; |