OSDN Git Service

doc:
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 5 May 2002 23:45:06 +0000 (23:45 +0000)
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 5 May 2002 23:45:06 +0000 (23:45 +0000)
* cpp.texi: Update multichar charconst docs.
testsuite:
* gcc.dg/cpp/charconst-3.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@53202 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/doc/cpp.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/charconst-3.c [new file with mode: 0644]

index 8d2de30..91effc8 100644 (file)
@@ -1,5 +1,10 @@
 2002-05-06  Neil Booth  <neil@daikokuya.demon.co.uk>
 
+doc:
+       * cpp.texi: Update multichar charconst docs.
+
+2002-05-06  Neil Booth  <neil@daikokuya.demon.co.uk>
+
        * cpplex.c (cpp_interpret_charconst): Sign-extend each
        character.  Don't ignore excess characters.  Treat
        multicharacter character constants as signed.
index 260efdc..7ba498d 100644 (file)
@@ -3508,17 +3508,25 @@ same column as it did in the original source file.
 
 @item The numeric value of character constants in preprocessor expressions.
 
-The preprocessor and compiler interpret character constants in the same
-way; escape sequences such as @samp{\a} are given the values they would
-have on the target machine.
+The preprocessor and compiler interpret character constants in the
+same way; i.e.@: escape sequences such as @samp{\a} are given the
+values they would have on the target machine.
 
 Multi-character character constants are interpreted a character at a
 time, shifting the previous result left by the number of bits per
-character on the host, and adding the new character.  For example, 'ab'
-on an 8-bit host would be interpreted as @w{'a' * 256 + 'b'}.  If there
-are more characters in the constant than can fit in the widest native
-integer type on the host, usually a @code{long}, the excess characters
-are ignored and a diagnostic is given.
+target character and adding the sign-extended value of the new
+character.  They have type @code{int}, and are treated as signed
+regardless of whether single characters are signed or not.  If there
+are more characters in the constant than would fit in the target
+@code{int}, a diagnostic is given, and the excess leading characters
+are ignored.  This methodology is not fully compatible with versions
+3.1 and earlier of GCC, which used a confusing and inconsistent
+valuation technique.
+
+For example, 'ab' for a target with an 8-bit @code{char} would be
+interpreted as @w{'a' * 256 + 'b'}, and 'a\234' as @w{'a' * 256 +
+'\234'}.  GCC 3.1 and earlier would give a different value for the
+latter example, probably @w{'a' * 256 + (unsigned char) '\234'}.
 
 @item Source file inclusion.
 
index 29463de..7bb4ca5 100644 (file)
@@ -1,3 +1,7 @@
+2002-05-06  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * gcc.dg/cpp/charconst-3.c: New test.
+
 2002-05-05  Neil Booth  <neil@daikokuya.demon.co.uk>
 
        * gcc.dg/cpp/charconst.c: Update tests.
diff --git a/gcc/testsuite/gcc.dg/cpp/charconst-3.c b/gcc/testsuite/gcc.dg/cpp/charconst-3.c
new file mode 100644 (file)
index 0000000..86fcf78
--- /dev/null
@@ -0,0 +1,40 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc.  */
+
+/* { dg-do compile } */
+/* { dg-options -Wno-multichar } */
+
+/* This tests values and signedness of multichar charconsts.
+
+   Neil Booth, 5 May 2002.  */
+
+#include <limits.h>
+
+int main ()
+{
+  /* These tests require at least 2-byte ints.  8-)  */
+#if INT_MAX > 127
+  int scale = (int) (unsigned char) -1 + 1;
+
+  if ('ab' != ('a' * scale + 'b'))
+    abort ();
+
+  if ('\234b' != ('\234' * scale + 'b'))
+    abort ();
+
+  if ('b\234' != ('b' * scale + '\234'))
+    abort ();
+
+  /* Multichar charconsts have type int and should be signed.  */
+#if INT_MAX == 32767
+  if ('\234a' > 0)
+    abort ();
+#elif INT_MAX == 2147483647
+  if ('\234aaa' > 0)
+    abort ();
+#elif INT_MAX == 9223372036854775807
+  if ('\234aaaaaaa' > 0)
+    abort ();
+#endif
+#endif
+  return 0;
+}