diff options
author | Neil Booth <neilb@earthling.net> | 2000-07-08 02:18:25 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2000-07-08 02:18:25 +0000 |
commit | 563dd08adfa12573fdecf9669fdf685fef5fd360 (patch) | |
tree | 9ca49cb51958d754a1e1218f2ee16625c7cb8dc6 /gcc/testsuite/gcc.dg | |
parent | 0828a0bd1b6f503880c694f106c8424967cb38aa (diff) | |
download | gcc-563dd08adfa12573fdecf9669fdf685fef5fd360.zip gcc-563dd08adfa12573fdecf9669fdf685fef5fd360.tar.gz gcc-563dd08adfa12573fdecf9669fdf685fef5fd360.tar.bz2 |
cpphash.c (is__va_args__): New function.
* cpphash.c (is__va_args__): New function.
(count_params): Fix line reported in error messages. Use
is__va_args__. Don't return ')' on error. Flag GNU style
rest args macro definitions.
(parse_define): Check macro name is not __VA_ARGS__.
(save_expansion): Check identifier in non-varargs-macro is
not __VA_ARGS__. Don't flag GNU_VARARGS.
* cpplex.c (parse_args): Accept no argument iff GNU_REST_ARGS.
(maybe_paste_with_next): Use per-macro GNU_REST_ARGS rather
than per-token GNU_VARARGS.
* cpplib.h (GNU_VARARGS): Remove.
(GNU_REST_ARGS): New.
* gcc.dg/cpp/macsyntx.c: New tests.
From-SVN: r34919
Diffstat (limited to 'gcc/testsuite/gcc.dg')
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/macsyntx.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/cpp/macsyntx.c b/gcc/testsuite/gcc.dg/cpp/macsyntx.c new file mode 100644 index 0000000..baa69d1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/macsyntx.c @@ -0,0 +1,72 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. */ + +/* { dg-do preprocess } */ +/* { dg-options -pedantic } */ + +/* Tests macro syntax, for both definition and invocation, including:- + + o Full range of macro definition semantics. + o No. of arguments supplied to function-like macros. + o Odd GNU rest args behaviour. + o Macro arguments do not flow into the rest of the file. */ + + +/* Test basic macro definition syntax. The macros are all called + "foo" deliberately to provoke an (excess) redefinition warning in + case the macros succeed in being entered in the macro hash table + despite being an error. + + Split a couple of the lines to check that the errors appear on the + right line (i.e. are associated with the correct token). */ + +#define ; /* { dg-error "identifier" } */ +#define SEMI; /* { dg-warning "space" } */ +#define foo(X /* { dg-error "missing" } */ +#define foo\ +(X,) /* { dg-error "parameter name" } */ +#define foo(, X) /* { dg-error "parameter name" } */ +#define foo(X, X) /* { dg-error "duplicate" } */ +#define foo(X Y) /* { dg-error "comma" } */ +#define foo(() /* { dg-error "illegal token" } */ +#define foo(..., X) /* { dg-error "missing" } */ +#define foo \ +__VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */ +#define foo(__VA_ARGS__) /* { dg-warning "__VA_ARGS__" } */ +#define foo(...) __VA_ARGS__ /* OK. */ +#define __VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */ + +/* test # of supplied arguments. */ +#define none() +#define one(x) +#define two(x, y) +#define var0(...) +#define var1(x, ...) +none() /* OK. */ +none(ichi) /* { dg-error "too many" } */ +one() /* OK. */ +one(ichi) /* OK. */ +one(ichi\ +, ni) /* { dg-error "too many" } */ +two(ichi) /* { dg-error "insufficient" } */ +var0() /* OK. */ +var0(ichi) /* OK. */ +var1() /* { dg-error "insufficient" } */ +var1(ichi) /* { dg-error "insufficient" } */ +var1(ichi, ni) /* OK. */ + +/* This tests two deprecated oddities of GNU rest args - omitting a + comma is OK, and backtracking a token on pasting an empty rest + args. */ +#define rest(x, y...) x ## y /* { dg-warning "ISO C" } */ +rest(ichi,) /* { dg-warning "deprecated" } */ +rest(ichi) /* { dg-warning "deprecated" } */ +#if 23 != rest(2, 3) /* OK, no warning. */ +#error 23 != 23 !! +#endif + +/* Test that we don't allow arguments to flow into the rest of the + file. */ +#define half_invocation do_nowt(2 +#define do_nowt(x) x +half_invocation ) /* OK. */ +do_nowt (half_invocation)) /* { dg-error "unterminated invocation" } */ |