diff --git a/gcc/testsuite/gcc.dg/cpp/pr118674.c b/gcc/testsuite/gcc.dg/cpp/pr118674.c new file mode 100644 index 000000000000..00ea438eeb2a --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr118674.c @@ -0,0 +1,5 @@ +/* PR preprocessor/118674 */ +/* { dg-do preprocess } */ +#define M(__VA_ARGS__, ...) +/* { dg-error "'__VA_ARGS__' can only appear in the expansion of a C99 variadic macro" "" { target *-*-* } .-1 } */ +/* { dg-error "duplicate macro parameter '__VA_ARGS__'" "" { target *-*-* } .-2 } */ diff --git a/libcpp/macro.cc b/libcpp/macro.cc index aa430e466408..be2571034718 100644 --- a/libcpp/macro.cc +++ b/libcpp/macro.cc @@ -3610,9 +3610,10 @@ parse_params (cpp_reader *pfile, unsigned *n_ptr, bool *variadic_ptr) if (!prev_ident) { /* An ISO bare ellipsis. */ - _cpp_save_parameter (pfile, nparms, - pfile->spec_nodes.n__VA_ARGS__, - pfile->spec_nodes.n__VA_ARGS__); + if (!_cpp_save_parameter (pfile, nparms, + pfile->spec_nodes.n__VA_ARGS__, + pfile->spec_nodes.n__VA_ARGS__)) + goto out; nparms++; pfile->state.va_args_ok = 1; if (! CPP_OPTION (pfile, c99)