diff options
author | Neil Booth <neil@daikokuya.demon.co.uk> | 2002-02-27 07:24:53 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2002-02-27 07:24:53 +0000 |
commit | e808ec9c71e52aa64bdb4579ad2ef75802b7bcb5 (patch) | |
tree | 7ffd19f1f5d3104b1545c9af4c64c746cda65cbc /gcc/doc/cpp.texi | |
parent | f585a35687df424814b57fd201253c11a19795f5 (diff) | |
download | gcc-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/doc/cpp.texi')
-rw-r--r-- | gcc/doc/cpp.texi | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi index d672e57..9e28e92 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -121,6 +121,7 @@ Macros * Variadic Macros:: * Predefined Macros:: * Undefining and Redefining Macros:: +* Directives Within Macro Arguments:: * Macro Pitfalls:: Predefined Macros @@ -1115,6 +1116,7 @@ macros when you are compiling C++. * Variadic Macros:: * Predefined Macros:: * Undefining and Redefining Macros:: +* Directives Within Macro Arguments:: * Macro Pitfalls:: @end menu @@ -2116,6 +2118,48 @@ the same, the redefinition is silently ignored. This allows, for instance, two different headers to define a common macro. The preprocessor will only complain if the definitions do not match. +@node Directives Within Macro Arguments +@section Directives Within Macro Arguments +@cindex macro arguments and directives + +Occasionally it is convenient to use preprocessor directives within +the arguments of a macro. The C and C++ standards declare that +behavior in these cases is undefined. + +Versions of GNU CPP prior to 3.2 would reject such constructs with an +error message. This was the only syntactic difference between normal +functions and function-like macros, so it seemed attractive to remove +this limitation, and people would often be surprised that they could +not use macros in this way. Moreover, sometimes people would use +conditional compilation in the argument list to a normal library +function like @samp{printf}, only to find that after a library upgrade +@samp{printf} had changed to be a function-like macro, and their code +would no longer compile. So from version 3.2 we changed CPP to +successfully process arbitrary directives within macro arguments in +exactly the same way as it would have processed the directive were the +function-like macro invocation not present. + +If, within a macro invocation, that macro is redefined, then the new +definition takes effect in time for argument pre-expansion, but the +original definition is still used for argument replacement. Here is a +pathological example: + +@smallexample +#define f(x) x x +f (1 +#undef f +#define f 2 +f) +@end smallexample + +@noindent which expands to + +@smallexample +1 2 1 2 +@end smallexample + +@noindent with the semantics described above. + @node Macro Pitfalls @section Macro Pitfalls @cindex problems with macros |