PR preprocessor/12935 preprocessor/12952 preprocessor/13046

PR preprocessor/12935 preprocessor/12952 preprocessor/13046
	* cpplib.c (prepare_directive_trad): Clear skipping only in
	#if and #elif directives.
	(do_undef): Call the handler even if the identifier is not a macro.
	* cpptrad.c (scan_parameters): Emit an error message.
	(_cpp_create_trad_definition): Remember the params list even on
	failure.
	* testsuite/gcc.dg/cpp/trad/macro.c: New tests.

From-SVN: r74562
This commit is contained in:
Neil Booth 2003-12-12 07:00:29 +00:00 committed by Neil Booth
parent d2b6eb76fa
commit 45f2492c99
5 changed files with 51 additions and 13 deletions

View File

@ -1,3 +1,13 @@
2003-12-12 Neil Booth <neil@daikokuya.co.uk>
PR preprocessor/12935 preprocessor/12952 preprocessor/13046
* cpplib.c (prepare_directive_trad): Clear skipping only in
#if and #elif directives.
(do_undef): Call the handler even if the identifier is not a macro.
* cpptrad.c (scan_parameters): Emit an error message.
(_cpp_create_trad_definition): Remember the params list even on
failure.
2003-12-11 Zack Weinberg <zack@codesourcery.com>
* arm.c (ARM_ADDRESS_COST, THUMB_ADDRESS_COST): Convert macros

View File

@ -272,14 +272,17 @@ prepare_directive_trad (cpp_reader *pfile)
&& ! (pfile->directive->flags & EXPAND));
bool was_skipping = pfile->state.skipping;
pfile->state.skipping = false;
pfile->state.in_expression = (pfile->directive == &dtable[T_IF]
|| pfile->directive == &dtable[T_ELIF]);
if (pfile->state.in_expression)
pfile->state.skipping = false;
if (no_expand)
pfile->state.prevent_expansion++;
_cpp_scan_out_logical_line (pfile, NULL);
if (no_expand)
pfile->state.prevent_expansion--;
pfile->state.skipping = was_skipping;
_cpp_overlay_buffer (pfile, pfile->out.base,
pfile->out.cur - pfile->out.base);
@ -520,22 +523,26 @@ do_undef (cpp_reader *pfile)
{
cpp_hashnode *node = lex_macro_node (pfile);
/* 6.10.3.5 paragraph 2: [#undef] is ignored if the specified identifier
is not currently defined as a macro name. */
if (node && node->type == NT_MACRO)
if (node)
{
if (pfile->cb.undef)
pfile->cb.undef (pfile, pfile->directive_line, node);
if (node->flags & NODE_WARN)
cpp_error (pfile, CPP_DL_WARNING,
"undefining \"%s\"", NODE_NAME (node));
/* 6.10.3.5 paragraph 2: [#undef] is ignored if the specified
identifier is not currently defined as a macro name. */
if (node->type == NT_MACRO)
{
if (node->flags & NODE_WARN)
cpp_error (pfile, CPP_DL_WARNING,
"undefining \"%s\"", NODE_NAME (node));
if (CPP_OPTION (pfile, warn_unused_macros))
_cpp_warn_if_unused_macro (pfile, node, NULL);
if (CPP_OPTION (pfile, warn_unused_macros))
_cpp_warn_if_unused_macro (pfile, node, NULL);
_cpp_free_definition (node);
_cpp_free_definition (node);
}
}
check_eol (pfile);
}

View File

@ -907,6 +907,9 @@ scan_parameters (cpp_reader *pfile, cpp_macro *macro)
break;
}
if (!ok)
cpp_error (pfile, CPP_DL_ERROR, "syntax error in macro parameter list");
CUR (pfile->context) = cur + (*cur == ')');
return ok;
@ -982,14 +985,17 @@ _cpp_create_trad_definition (cpp_reader *pfile, cpp_macro *macro)
/* Is this a function-like macro? */
if (* CUR (context) == '(')
{
bool ok = scan_parameters (pfile, macro);
/* Remember the params so we can clear NODE_MACRO_ARG flags. */
macro->params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff);
/* Setting macro to NULL indicates an error occurred, and
prevents unnecessary work in _cpp_scan_out_logical_line. */
if (!scan_parameters (pfile, macro))
if (!ok)
macro = NULL;
else
{
/* Success. Commit the parameter array. */
macro->params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff);
BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->params[macro->paramc];
macro->fun_like = 1;
}

View File

@ -1,3 +1,7 @@
2003-12-12 Neil Booth <neil@daikokuya.co.uk>
* testsuite/gcc.dg/cpp/trad/macro.c: New tests.
2003-12-11 Zack Weinberg <zack@codesourcery.com>
* gcc.c-torture/execute/wchar_t-1.x: Delete.

View File

@ -0,0 +1,11 @@
/* Test that varargs are rejected, and that we don't complain about
macro args in skipped blocks. */
/* { dg-do preprocess } */
#define f(x)
#define g(x, y...) /* { dg-error "macro parameter list" } */
#if 0
#define f(a,b) /* { dg-bogus "passed 2 arguments" } */
#endif