diff options
Diffstat (limited to 'contrib/gcc/cppmacro.c')
-rw-r--r-- | contrib/gcc/cppmacro.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/contrib/gcc/cppmacro.c b/contrib/gcc/cppmacro.c index b351f96..c85ac21 100644 --- a/contrib/gcc/cppmacro.c +++ b/contrib/gcc/cppmacro.c @@ -613,7 +613,20 @@ collect_args (pfile, node) } if (!error) - return base_buff; + { + /* GCC has special semantics for , ## b where b is a varargs + parameter: we remove the comma if b was omitted entirely. + If b was merely an empty argument, the comma is retained. + If the macro takes just one (varargs) parameter, then we + retain the comma only if we are standards conforming. + + If FIRST is NULL replace_args () swallows the comma. */ + if (macro->variadic && (argc < macro->paramc + || (argc == 1 && args[0].count == 0 + && !CPP_OPTION (pfile, std)))) + args[macro->paramc - 1].first = NULL; + return base_buff; + } _cpp_release_buff (pfile, base_buff); return NULL; @@ -673,6 +686,8 @@ enter_macro_context (pfile, node) /* The presence of a macro invalidates a file's controlling macro. */ pfile->mi_valid = false; + pfile->state.angled_headers = false; + /* Handle standard macros. */ if (! (node->flags & NODE_BUILTIN)) { @@ -797,15 +812,13 @@ replace_args (pfile, node, args) count = arg->count, from = arg->first; if (dest != first) { - /* GCC has special semantics for , ## b where b is a - varargs parameter: the comma disappears if b was - given no actual arguments (not merely if b is an - empty argument); otherwise the paste flag is removed. */ if (dest[-1]->type == CPP_COMMA && macro->variadic && src->val.arg_no == macro->paramc) { - if (count == 0) + /* Swallow a pasted comma if from == NULL, otherwise + drop the paste flag. */ + if (from == NULL) dest--; else paste_flag = dest - 1; @@ -1529,7 +1542,7 @@ cpp_macro_definition (pfile, node) } /* Calculate length. */ - len = NODE_LEN (node) + 1; /* ' ' */ + len = NODE_LEN (node) + 2; /* ' ' and NUL. */ if (macro->fun_like) { len += 4; /* "()" plus possible final ".." of named |