summaryrefslogtreecommitdiff
path: root/gcc/cppmacro.c
diff options
context:
space:
mode:
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2002-08-06 20:35:46 +0000
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2002-08-06 20:35:46 +0000
commited909a0959acaa751bb78bcf3b7c44c3c07942a0 (patch)
tree6bf828a9fcc79198ebca01c572aeea673134e23a /gcc/cppmacro.c
parent1d6eb2a0734ba49f4477fcff84d920ab5e45e5a9 (diff)
downloadgcc-ed909a0959acaa751bb78bcf3b7c44c3c07942a0.tar.gz
* cppinit.c (struct lang_flags): Rename trigraphs std.
(set_lang): Update. * cpplib.h (struct cpp_options): New member std. * cppmacro.c (_cpp_builtin_macro_text): Use std. (collect_args): Flag whether to swallow a possible future comma pasted with varargs. (replace_args): Use this flag. * doc/cpp.texi: Update varargs extension documentation. testsuite: * gcc.dg/cpp/vararg3.c, gcc.dg/cpp/vararg4.c: New tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@56077 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cppmacro.c')
-rw-r--r--gcc/cppmacro.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c
index f0986b353cb..76030903089 100644
--- a/gcc/cppmacro.c
+++ b/gcc/cppmacro.c
@@ -191,8 +191,7 @@ _cpp_builtin_macro_text (pfile, node)
enum c_lang lang = CPP_OPTION (pfile, lang);
if (CPP_IN_SYSTEM_HEADER (pfile)
&& CPP_OPTION (pfile, stdc_0_in_system_headers)
- && !(lang == CLK_STDC89 || lang == CLK_STDC94
- || lang == CLK_STDC99)) /* || lang == CLK_CXX98 ? */
+ && !CPP_OPTION (pfile,std))
number = 0;
else
number = 1;
@@ -672,7 +671,20 @@ collect_args (pfile, node)
if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
argc = 0;
if (_cpp_arguments_ok (pfile, macro, node, argc))
- 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;
+ }
}
/* An error occurred. */
@@ -861,15 +873,13 @@ replace_args (pfile, node, macro, 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;