diff options
author | Neil Booth <neil@daikokuya.co.uk> | 2003-12-12 07:00:29 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2003-12-12 07:00:29 +0000 |
commit | 45f2492c99625b7dff5e9eced1969861d3fc1ca1 (patch) | |
tree | 4614d26a7b81e6a3878d634b99ee0a34b5e069e1 /gcc | |
parent | d2b6eb76fa7c35f512f8f8dd16b027a525550460 (diff) | |
download | gcc-45f2492c99625b7dff5e9eced1969861d3fc1ca1.zip gcc-45f2492c99625b7dff5e9eced1969861d3fc1ca1.tar.gz gcc-45f2492c99625b7dff5e9eced1969861d3fc1ca1.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/cpplib.c | 27 | ||||
-rw-r--r-- | gcc/cpptrad.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/trad/macro.c | 11 |
5 files changed, 51 insertions, 13 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 08e75f5..ad91bf6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 69995d4..2b213cb 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -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); } diff --git a/gcc/cpptrad.c b/gcc/cpptrad.c index 6da19cc..08636ed 100644 --- a/gcc/cpptrad.c +++ b/gcc/cpptrad.c @@ -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 *) ¯o->params[macro->paramc]; macro->fun_like = 1; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2dfae58..358b093 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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. diff --git a/gcc/testsuite/gcc.dg/cpp/trad/macro.c b/gcc/testsuite/gcc.dg/cpp/trad/macro.c new file mode 100644 index 0000000..164b4ec --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/macro.c @@ -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 |