OSDN Git Service

* cpptrad.c (struct fun_macro): Add line number.
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 22 Jun 2002 11:08:20 +0000 (11:08 +0000)
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 22 Jun 2002 11:08:20 +0000 (11:08 +0000)
(scan_out_logical_line): Set it, and use it to report unterminated
macro invocations.
testsuite:
* gcc.dg/cpp/trad/comment-2.c. gcc.dg/cpp/trad/funlike-2.c,
gcc.dg/cpp/trad/funlike.c, gcc.dg/cpp/trad/funlike-3.c,
gcc.dg/cpp/trad/literals-1.c, gcc.dg/cpp/trad/literals-2.c,
gcc.dg/cpp/trad/macroargs.c, gcc.dg/cpp/trad/quote.c: New tests.

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

gcc/ChangeLog
gcc/cpptrad.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/trad/comment-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/funlike-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/funlike-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/funlike.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/literals-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/literals-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/macroargs.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/quote.c [new file with mode: 0644]

index ea2f1e5..0d3a098 100644 (file)
@@ -1,3 +1,9 @@
+2002-06-22  Neil Booth  <neil@daikokuya.co.uk>
+
+       * cpptrad.c (struct fun_macro): Add line number.
+       (scan_out_logical_line): Set it, and use it to report unterminated
+       macro invocations.
+
 2002-06-21  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * genautomata.c (copy_node, VLA_PTR_CREATE, VLA_PTR_EXPAND,
index b3413d0..22320c4 100644 (file)
@@ -59,6 +59,9 @@ struct fun_macro
   /* The offset of the macro name in the output buffer.  */
   size_t offset;
 
+  /* The line the macro name appeared on.  */
+  unsigned int line;
+
   /* Zero-based index of argument being currently lexed.  */
   unsigned int argc;
 };
@@ -586,6 +589,7 @@ scan_out_logical_line (pfile, macro)
                    {
                      maybe_start_funlike (pfile, node, out_start, &fmacro);
                      lex_state = ls_fun_open;
+                     fmacro.line = pfile->line;
                      continue;
                    }
                  else
@@ -721,9 +725,9 @@ scan_out_logical_line (pfile, macro)
     _cpp_release_buff (pfile, fmacro.buff);
 
   if (lex_state == ls_fun_close)
-    cpp_error (pfile, DL_ERROR,
-              "unterminated argument list invoking macro \"%s\"",
-              NODE_NAME (fmacro.node));
+    cpp_error_with_line (pfile, DL_ERROR, fmacro.line, 0,
+                        "unterminated argument list invoking macro \"%s\"",
+                        NODE_NAME (fmacro.node));
 }
 
 /* Push a context holding the replacement text of the macro NODE on
index 75b2189..52b8c9b 100644 (file)
@@ -1,3 +1,10 @@
+2002-06-22  Neil Booth  <neil@daikokuya.co.uk>
+
+       * gcc.dg/cpp/trad/comment-2.c. gcc.dg/cpp/trad/funlike-2.c,
+       gcc.dg/cpp/trad/funlike.c, gcc.dg/cpp/trad/funlike-3.c,
+       gcc.dg/cpp/trad/literals-1.c, gcc.dg/cpp/trad/literals-2.c,
+       gcc.dg/cpp/trad/macroargs.c, gcc.dg/cpp/trad/quote.c: New tests.
+
 2002-06-21  Neil Booth  <neil@daikokuya.co.uk>
 
        * gcc.dg/cpp/trad: New directory with traditional tests copied
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/comment-2.c b/gcc/testsuite/gcc.dg/cpp/trad/comment-2.c
new file mode 100644 (file)
index 0000000..8d54e3a
--- /dev/null
@@ -0,0 +1,11 @@
+/* Test for warning of nested comments.  */
+
+/* { dg-do preprocess } */
+
+/* { dg-options "-traditional-cpp -Wcomments" }
+
+/* /* */   /* { dg-warning "within comment" } */
+
+/*
+
+ /* { dg-warning "within comment" } */
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/funlike-2.c b/gcc/testsuite/gcc.dg/cpp/trad/funlike-2.c
new file mode 100644 (file)
index 0000000..edcf2ab
--- /dev/null
@@ -0,0 +1,23 @@
+/* Test that nested commas and parentheses in macro arguments are
+   OK.  */
+
+/* { dg-do preprocess } */
+
+#define f(x) x
+#define g(x, y) x y
+
+#if f((1)) != 1
+# error                /* { dg-bogus "error" "nested parens 1" } */
+#endif
+
+#if f((1, 2)) != 2
+# error                /* { dg-bogus "error" "nested comma 1" } */
+#endif
+
+#if g(, (1)) != 1
+# error                /* { dg-bogus "error" "nested parens 2" } */
+#endif
+
+#if g((1, 2), + 3) != 5
+# error                /* { dg-bogus "error" "nested comma 2" } */
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/funlike-3.c b/gcc/testsuite/gcc.dg/cpp/trad/funlike-3.c
new file mode 100644 (file)
index 0000000..5300afb
--- /dev/null
@@ -0,0 +1,12 @@
+/* Test that function-like macros are restricted to directives, and
+   that unterminated ones are warned about.  */
+
+/* { dg-do preprocess } */
+
+#define f(x) x
+
+#if 2 f(/* { dg-error "unterminated" "unterminated macro in directive" } */
+)
+#endif
+
+f( /* { dg-error "unterminated" "unterminated macro" } */
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/funlike.c b/gcc/testsuite/gcc.dg/cpp/trad/funlike.c
new file mode 100644 (file)
index 0000000..db550d5
--- /dev/null
@@ -0,0 +1,25 @@
+/* Test that undefined names evaluate to zero, that macros after a
+   funlike macro are expanded, and that if it is a '(' the funlike
+   macro is not treated as such.  */
+
+/* { dg-do preprocess } */
+
+#define f(x) x
+#define h != 0
+#define i
+#define paren (
+
+#if f != 0
+# error                /* { dg-bogus "error" "undefined name" } */
+#endif
+
+#if f h
+# error                /* { dg-bogus "error" "h not expanded" } */
+#endif
+
+#if f i
+# error                /* { dg-bogus "error" "empty macro" } */
+#endif
+
+#if f paren 6) /* { dg-error "missing binary" "macro-expanded parenthesis" } */
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/literals-1.c b/gcc/testsuite/gcc.dg/cpp/trad/literals-1.c
new file mode 100644 (file)
index 0000000..7fde0d5
--- /dev/null
@@ -0,0 +1,28 @@
+/* Test that (what looks like) comments are not recognised in literals
+   and that quotes within quotes do not confused the preprocessor.  */
+
+/* { dg-do run } */
+
+extern void abort (void);
+
+int main ()
+{
+  const char *str1 = "/*";
+  const char *str2 = "'";
+
+  if (str1[0] != '/' || str1[1] != '*' || str1[2] != '\0')
+    abort ();
+
+  if (str2[0] != '\'' || str2[1] != '\0')
+    abort ();
+
+#if '"' != '\"'
+#  error /* { dg-bogus "error" "double quote in charconst" } */
+#endif
+
+#if !'\''
+#  error quote /* { dg-bogus "quote" "quote in charconst" } */
+#endif
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/literals-2.c b/gcc/testsuite/gcc.dg/cpp/trad/literals-2.c
new file mode 100644 (file)
index 0000000..807bb0d
--- /dev/null
@@ -0,0 +1,8 @@
+/* Test that unterminated quotes in CPP expressions are
+   recognized.  */
+
+/* { dg-do preprocess } */
+
+/* { dg-error "missing terminating" "bad charconst" { target *-*-* } 7 } */
+#if 'x
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/macroargs.c b/gcc/testsuite/gcc.dg/cpp/trad/macroargs.c
new file mode 100644 (file)
index 0000000..12effa7
--- /dev/null
@@ -0,0 +1,24 @@
+/* Test that whitespace in arguments is preserved, and that each
+   newline in macro arguments become a space.  */
+
+/* { dg-do run } */
+
+#define f(x, y) "x y"
+
+extern void abort (void);
+
+int main ()
+{
+  const char *str1 = f( foo ,bar);
+  const char *str2 = f(
+foo
+,bar);
+
+  if (strcmp (str1, " foo  bar"))
+    abort ();
+
+  if (strcmp (str1, str2))
+    abort ();
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/quote.c b/gcc/testsuite/gcc.dg/cpp/trad/quote.c
new file mode 100644 (file)
index 0000000..f8e6170
--- /dev/null
@@ -0,0 +1,6 @@
+/* Test that unterminated quotes are OK when only preprocessing.  */
+
+/* { dg-do preprocess } */
+
+/* { dg-bogus "unterminated" } */  'x
+/* { dg-bogus "unterminated" } */  "x