aboutsummaryrefslogtreecommitdiff
path: root/gcc/cpplib.c
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.demon.co.uk>2002-02-27 07:24:53 +0000
committerNeil Booth <neil@gcc.gnu.org>2002-02-27 07:24:53 +0000
commite808ec9c71e52aa64bdb4579ad2ef75802b7bcb5 (patch)
tree7ffd19f1f5d3104b1545c9af4c64c746cda65cbc /gcc/cpplib.c
parentf585a35687df424814b57fd201253c11a19795f5 (diff)
downloadgcc-e808ec9c71e52aa64bdb4579ad2ef75802b7bcb5.zip
gcc-e808ec9c71e52aa64bdb4579ad2ef75802b7bcb5.tar.gz
gcc-e808ec9c71e52aa64bdb4579ad2ef75802b7bcb5.tar.bz2
cpplex.c (_cpp_lex_token): Handle directives in macro arguments.
* cpplex.c (_cpp_lex_token): Handle directives in macro arguments. * cpplib.c (_cpp_handle_directive): Save and restore state if parsing macro args when entering a directive. * cppmacro.c (collect_args): No need to handle directives in macro arguments. (enter_macro_context, replace_args): Use the original macro definition in case it was redefined whilst collecting arguments. doc: * cpp.texi: Update. testsuite: * gcc.dg/cpp/undef1.c: Remove. * gcc.dg/cpp/directiv.c: Update. * gcc.dg/cpp/mac-dir-1.c, mac-dir-2.c: New tests. From-SVN: r50091
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r--gcc/cpplib.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c
index 1a38f01..d9f95bd 100644
--- a/gcc/cpplib.c
+++ b/gcc/cpplib.c
@@ -316,8 +316,17 @@ _cpp_handle_directive (pfile, indented)
{
const directive *dir = 0;
const cpp_token *dname;
+ bool was_parsing_args = pfile->state.parsing_args;
int skip = 1;
+ if (was_parsing_args)
+ {
+ if (CPP_OPTION (pfile, pedantic))
+ cpp_pedwarn (pfile,
+ "embedding a directive within macro arguments is not portable");
+ pfile->state.parsing_args = 0;
+ pfile->state.prevent_expansion = 0;
+ }
start_directive (pfile);
dname = _cpp_lex_token (pfile);
@@ -393,6 +402,13 @@ _cpp_handle_directive (pfile, indented)
_cpp_backup_tokens (pfile, 1);
end_directive (pfile, skip);
+ if (was_parsing_args)
+ {
+ /* Restore state when within macro args. */
+ pfile->state.parsing_args = 2;
+ pfile->state.prevent_expansion = 1;
+ pfile->buffer->saved_flags |= PREV_WHITE;
+ }
return skip;
}