(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
+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,
/* 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;
};
{
maybe_start_funlike (pfile, node, out_start, &fmacro);
lex_state = ls_fun_open;
+ fmacro.line = pfile->line;
continue;
}
else
_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
+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
--- /dev/null
+/* Test for warning of nested comments. */
+
+/* { dg-do preprocess } */
+
+/* { dg-options "-traditional-cpp -Wcomments" }
+
+/* /* */ /* { dg-warning "within comment" } */
+
+/*
+
+ /* { dg-warning "within comment" } */
--- /dev/null
+/* 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
--- /dev/null
+/* 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" } */
--- /dev/null
+/* 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
--- /dev/null
+/* 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;
+}
--- /dev/null
+/* Test that unterminated quotes in CPP expressions are
+ recognized. */
+
+/* { dg-do preprocess } */
+
+/* { dg-error "missing terminating" "bad charconst" { target *-*-* } 7 } */
+#if 'x
+#endif
--- /dev/null
+/* 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;
+}
--- /dev/null
+/* Test that unterminated quotes are OK when only preprocessing. */
+
+/* { dg-do preprocess } */
+
+/* { dg-bogus "unterminated" } */ 'x
+/* { dg-bogus "unterminated" } */ "x