diff options
author | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-02-27 07:24:53 +0000 |
---|---|---|
committer | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-02-27 07:24:53 +0000 |
commit | d6af03689afcb6d54e5ce66a399f68753a2aea3e (patch) | |
tree | 7ffd19f1f5d3104b1545c9af4c64c746cda65cbc /gcc/testsuite | |
parent | fc54b737e45b3feef050092c62be54cf1b81c5a7 (diff) | |
download | gcc-d6af03689afcb6d54e5ce66a399f68753a2aea3e.tar.gz |
* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@50091 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/directiv.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/mac-dir-1.c | 34 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/mac-dir-2.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/undef1.c | 14 |
5 files changed, 57 insertions, 20 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b45bd6d7f49..ae4efb8fa76 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2002-02-27 Neil Booth <neil@daikokuya.demon.co.uk> + + * 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. + 2002-02-27 Michael Meissner <meissner@redhat.com> * gcc.c-torture/execute/20020226-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/cpp/directiv.c b/gcc/testsuite/gcc.dg/cpp/directiv.c index cbf4ac6501c..aafe2ec109d 100644 --- a/gcc/testsuite/gcc.dg/cpp/directiv.c +++ b/gcc/testsuite/gcc.dg/cpp/directiv.c @@ -25,16 +25,11 @@ EMPTY #define bar /* Our friend the null directive OK? */ # -/* Check that directives always start a line, even if in middle of - macro expansion. */ -#define func(x) x -func (2 /* { dg-error "unterminated" "" } */ -#define foobar /* { dg-error "directives may not" } */ - /* Check newlines end directives, even in function-like macro invocations. 6.10 paragraph 1. Note that the #if is still treated as a conditional, so there should be no errors about #endif without #if. */ +#define func(x) x #if func ( /* { dg-error "unterminated argument" } */ #endif diff --git a/gcc/testsuite/gcc.dg/cpp/mac-dir-1.c b/gcc/testsuite/gcc.dg/cpp/mac-dir-1.c new file mode 100644 index 00000000000..002c47f5f2b --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/mac-dir-1.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2002 Free Software Foundation, Inc. */ + +/* { dg-do preprocess } */ + +/* Source: Neil Booth, 26 Feb 2002. + + Test that we allow directives in macro arguments. */ + +/* { dg-do run } */ +/* { dg-options "" } */ + +#define f(x) x +extern void abort (void); + +int main () +{ + if (f ( +#if f(1) /* True. */ + 0)) /* False. */ +#else + 1)) +#endif + abort (); + + /* Outer f expands to original definition, f in argument expands + to new definition, so result is: if (1 != 2 - 1). */ + if (1 != f(2 +#undef f +#define f - 1 + f)) + abort (); + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/cpp/mac-dir-2.c b/gcc/testsuite/gcc.dg/cpp/mac-dir-2.c new file mode 100644 index 00000000000..b574cfd71cf --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/mac-dir-2.c @@ -0,0 +1,16 @@ +/* Copyright (C) 2002 Free Software Foundation, Inc. */ + +/* { dg-do preprocess } */ + +/* Source: Neil Booth, 26 Feb 2002. + + Test that we allow directives in macro arguments. */ + +/* { dg-do preprocess } */ + +#define f(x) x + +f ( +#if 1 /* { dg-warning "not portable" } */ +1) +#endif diff --git a/gcc/testsuite/gcc.dg/cpp/undef1.c b/gcc/testsuite/gcc.dg/cpp/undef1.c deleted file mode 100644 index 446fc93117d..00000000000 --- a/gcc/testsuite/gcc.dg/cpp/undef1.c +++ /dev/null @@ -1,14 +0,0 @@ -/* { dg-do preprocess } */ - -/* 6.9.3.11: ...If there are sequences of preprocessing tokens within - the list of arguments that would otherwise act as preprocessing - directives, the behavior is undefined. - - I choose to make this a hard error. It definitely should not cause - a core dump. */ - -#define foo(bar) bar - -foo( blah /* { dg-error "unterminated" "" } */ -#undef foo /* { dg-error "may not be used inside" "foo(#undef foo)" } */ - blah ) |