cpptrad.c (struct fun_macro): Add line number.

* cpptrad.c (struct fun_macro): Add line number.
	(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.

From-SVN: r54907
This commit is contained in:
Neil Booth 2002-06-22 11:08:20 +00:00 committed by Neil Booth
parent 112bae7721
commit 847c76c86a
11 changed files with 157 additions and 3 deletions

View 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,

View 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

View 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

View File

@ -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" } */

View File

@ -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

View File

@ -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" } */

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -0,0 +1,6 @@
/* Test that unterminated quotes are OK when only preprocessing. */
/* { dg-do preprocess } */
/* { dg-bogus "unterminated" } */ 'x
/* { dg-bogus "unterminated" } */ "x