cppexp.c (lex): Use %.*s to print non-NUL-terminated string.
authorZack Weinberg <zack@wolery.cumb.org>
Wed, 10 May 2000 19:29:20 +0000 (19:29 +0000)
committerZack Weinberg <zack@gcc.gnu.org>
Wed, 10 May 2000 19:29:20 +0000 (19:29 +0000)
* cppexp.c (lex): Use %.*s to print non-NUL-terminated string.
Make error message friendlier.

From-SVN: r33829

gcc/ChangeLog
gcc/cppexp.c
gcc/testsuite/gcc.dg/cpp-if4.c [new file with mode: 0644]

index 46a89c2..a942946 100644 (file)
@@ -1,5 +1,8 @@
 2000-05-10  Zack Weinberg  <zack@wolery.cumb.org>
 
+       * cppexp.c (lex): Use %.*s to print non-NUL-terminated string.
+       Make error message friendlier.
+
        * cpphash.h (struct hashnode): Use struct hack for name
        member.
        * cpphash.c (struct hashdummy): New.
index 00eaea7..7e99292 100644 (file)
@@ -466,8 +466,8 @@ lex (pfile, skip_evaluation)
                && tok_start[1] == toktab->operator[1])
                break;
          if (toktab->token == ERROR)
-           cpp_error (pfile, "'%s' not allowed in operand of #if",
-                      tok_start);
+           cpp_error (pfile, "'%.*s' is not allowed in #if expressions",
+                      (int) (tok_end - tok_start), tok_start);
          op.op = toktab->token; 
          return op;
        }
diff --git a/gcc/testsuite/gcc.dg/cpp-if4.c b/gcc/testsuite/gcc.dg/cpp-if4.c
new file mode 100644 (file)
index 0000000..84764fb
--- /dev/null
@@ -0,0 +1,8 @@
+/* Regression test for proper error message.  The token name isn't
+   NUL terminated, so we would print garbage after it.  */
+/* { dg-do compile } */
+
+#if 1 += 2   /* { dg-error "'\\+=' is not allowed" "+= in if" } */
+syntax_error
+#endif
+int foo;