From 95d3a6964cb0cedfa2e5112b8de75bd3f4fbfbed Mon Sep 17 00:00:00 2001 From: neil Date: Sat, 3 Mar 2001 22:14:08 +0000 Subject: [PATCH] * cpplex.c (_cpp_lex_token): Don't warn about directives in macro arguments when looking for the '('. * cppmacro.c (funlike_invocation_p): Set parsing_args to 2 when really parsing arguments; 1 when looking for '('. Always restore the lexer position. * gcc.dg/cpp/cppmacro7.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@40223 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 8 ++++++ gcc/cpplex.c | 60 +++++++++++++++++++-------------------- gcc/cppmacro.c | 8 ++++-- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.dg/cpp/macro7.c | 10 +++++++ 5 files changed, 56 insertions(+), 34 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/cpp/macro7.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a4f7d64429b..322d2410514 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,13 @@ 2001-03-03 Neil Booth + * cpplex.c (_cpp_lex_token): Don't warn about directives in + macro arguments when looking for the '('. + * cppmacro.c (funlike_invocation_p): Set parsing_args to + 2 when really parsing arguments; 1 when looking for '('. + Always restore the lexer position. + +2001-03-03 Neil Booth + * longlong.h (umul_ppmm): Don't use a multiline string. 2001-03-03 John David Anglin diff --git a/gcc/cpplex.c b/gcc/cpplex.c index 939951a4e7f..bd963038613 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -1171,38 +1171,36 @@ _cpp_lex_token (pfile, result) result->type = CPP_HASH; do_hash: - if (bol) + if (!bol) + break; + /* 6.10.3 paragraph 11: If there are sequences of preprocessing + tokens within the list of arguments that would otherwise act + as preprocessing directives, the behavior is undefined. + + This implementation will report a hard error, terminate the + macro invocation, and proceed to process the directive. */ + if (pfile->state.parsing_args) { - if (pfile->state.parsing_args) - { - /* 6.10.3 paragraph 11: If there are sequences of - preprocessing tokens within the list of arguments that - would otherwise act as preprocessing directives, the - behavior is undefined. - - This implementation will report a hard error, terminate - the macro invocation, and proceed to process the - directive. */ - cpp_error (pfile, - "directives may not be used inside a macro argument"); - - /* Put a '#' in lookahead, return CPP_EOF for parse_arg. */ - buffer->extra_char = buffer->read_ahead; - buffer->read_ahead = '#'; - pfile->state.next_bol = 1; - result->type = CPP_EOF; - - /* Get whitespace right - newline_in_args sets it. */ - if (pfile->lexer_pos.col == 1) - result->flags &= ~(PREV_WHITE | AVOID_LPASTE); - } - else - { - /* This is the hash introducing a directive. */ - if (_cpp_handle_directive (pfile, result->flags & PREV_WHITE)) - goto done_directive; /* bol still 1. */ - /* This is in fact an assembler #. */ - } + if (pfile->state.parsing_args == 2) + cpp_error (pfile, + "directives may not be used inside a macro argument"); + + /* Put a '#' in lookahead, return CPP_EOF for parse_arg. */ + buffer->extra_char = buffer->read_ahead; + buffer->read_ahead = '#'; + pfile->state.next_bol = 1; + result->type = CPP_EOF; + + /* Get whitespace right - newline_in_args sets it. */ + if (pfile->lexer_pos.col == 1) + result->flags &= ~(PREV_WHITE | AVOID_LPASTE); + } + else + { + /* This is the hash introducing a directive. */ + if (_cpp_handle_directive (pfile, result->flags & PREV_WHITE)) + goto done_directive; /* bol still 1. */ + /* This is in fact an assembler #. */ } break; diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c index d424a4146e9..2390ee43798 100644 --- a/gcc/cppmacro.c +++ b/gcc/cppmacro.c @@ -602,6 +602,7 @@ funlike_invocation_p (pfile, node, list) cpp_start_lookahead (pfile); cpp_get_token (pfile, &maybe_paren); cpp_stop_lookahead (pfile, maybe_paren.type == CPP_OPEN_PAREN); + pfile->state.parsing_args = 2; if (maybe_paren.type == CPP_OPEN_PAREN) args = parse_args (pfile, node); @@ -615,11 +616,12 @@ funlike_invocation_p (pfile, node, list) pfile->state.prevent_expansion--; pfile->state.parsing_args = 0; + /* Reset the position in case of failure. If success, the macro's + expansion appears where the name would have. */ + pfile->lexer_pos = macro_pos; + if (args) { - /* The macro's expansion appears where the name would have. */ - pfile->lexer_pos = macro_pos; - if (node->value.macro->paramc > 0) { /* Don't save tokens during pre-expansion. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5718cf43bbb..8e2e7b0399c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2001-03-03 Neil Booth + * gcc.dg/cpp/macro7.c: New test. + +2001-03-03 Neil Booth + * gcc.dg/cpp/multiline.c: Update. 2001-03-02 Nathan Sidwell diff --git a/gcc/testsuite/gcc.dg/cpp/macro7.c b/gcc/testsuite/gcc.dg/cpp/macro7.c new file mode 100644 index 00000000000..6f2c67c1080 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/macro7.c @@ -0,0 +1,10 @@ +/* { dg-do preprocess } */ + +/* Test we don't complain about directives in macro expansions when + looking for the '(' of a function-like macro. + + Submitter: Neil Booth. 3 Mar 2000. */ + +#define f(x) x +f +#define g -- 2.11.0