This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix __VA_OPT__ testsuite fallout
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>, Tom Tromey <tom at tromey dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 14 Nov 2017 09:30:25 +0100
- Subject: [PATCH] Fix __VA_OPT__ testsuite fallout
- Authentication-results: sourceware.org; auth=none
- References: <20170916214918.14930-1-tom@tromey.com> <alpine.LNX.2.20.13.1709171224470.23347@monopod.intra.ispras.ru> <87k20xbbq3.fsf@tromey.com> <87bmm9bacr.fsf@tromey.com> <877ewxba8z.fsf@tromey.com> <0811e75e-694c-1760-4960-82dfadee2c36@redhat.com> <87vaigossw.fsf@tromey.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
On Sun, Nov 12, 2017 at 12:33:03AM -0700, Tom Tromey wrote:
> if (argc < macro->paramc)
> {
> - /* As an extension, variadic arguments are allowed to not appear in
> + /* In C++2a (here the va_opt flag is used), and also as a GNU
> + extension, variadic arguments are allowed to not appear in
> the invocation at all.
> e.g. #define debug(format, args...) something
> debug("string");
> @@ -778,7 +928,8 @@ _cpp_arguments_ok (cpp_reader *pfile, cpp_macro *macro, const cpp_hashnode *node
>
> if (argc + 1 == macro->paramc && macro->variadic)
> {
> - if (CPP_PEDANTIC (pfile) && ! macro->syshdr)
> + if (CPP_PEDANTIC (pfile) && ! macro->syshdr
> + && ! CPP_OPTION (pfile, va_opt))
> {
> if (CPP_OPTION (pfile, cplusplus))
> cpp_error (pfile, CPP_DL_PEDWARN,
This change broke the macsyntx.c and sysmac1.c tests, which were expecting
the "requires at least one" pedwarn, but were using -std=gnu99 which now
enables the __VA_OPT__ support and thus allows as many arguments in the
invocation as there are parameters in the macro definition (excluding the
...).
The following patch turns those into dg-bogus and adds copies of the test
that use -std=c99 that doesn't include __VA_OPT__ support and check for the
pedwarns there.
Tested on x86_64-linux, ok for trunk?
2017-11-14 Jakub Jelinek <jakub@redhat.com>
* gcc.dg/cpp/macsyntx.c (var1, rest): Don't expect
"requires at least one" warning.
* gcc.dg/cpp/sysmac1.c (foo): Likewise.
* gcc.dg/cpp/macsyntx2.c: New test.
* gcc.dg/cpp/sysmac3.c: New test.
* gcc.dg/cpp/sysmac3.h: New file.
--- gcc/testsuite/gcc.dg/cpp/macsyntx.c.jj 2014-07-14 09:30:29.000000000 +0200
+++ gcc/testsuite/gcc.dg/cpp/macsyntx.c 2017-11-14 09:21:16.794091580 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 Free Software Foundation, Inc. */
+/* Copyright (C) 2000-2017 Free Software Foundation, Inc. */
/* { dg-do preprocess } */
/* { dg-options "-pedantic -std=gnu99" } */
@@ -51,15 +51,15 @@ one(ichi\
two(ichi) /* { dg-error "requires 2" } */
var0() /* OK. */
var0(ichi) /* OK. */
-var1() /* { dg-warning "requires at least one" } */
-var1(ichi) /* { dg-warning "requires at least one" } */
+var1() /* { dg-bogus "requires at least one" } */
+var1(ichi) /* { dg-bogus "requires at least one" } */
var1(ichi, ni) /* OK. */
/* This tests two 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,) /* OK. */
-rest(ichi) /* { dg-warning "requires at least one" } */
+rest(ichi) /* { dg-bogus "requires at least one" } */
#if 23 != rest(2, 3) /* OK, no warning. */
#error 23 != 23 !!
#endif
--- gcc/testsuite/gcc.dg/cpp/sysmac1.c.jj 2014-07-14 09:30:29.000000000 +0200
+++ gcc/testsuite/gcc.dg/cpp/sysmac1.c 2017-11-14 09:19:07.581694406 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001 Free Software Foundation, Inc. */
+/* Copyright (C) 2001-2017 Free Software Foundation, Inc. */
/* { dg-do preprocess } */
/* { dg-options "-std=gnu99 -pedantic -Wtraditional -ftrack-macro-expansion=0" } */
@@ -22,5 +22,5 @@
(str); /* { dg-warning "used with arguments" } */
(sys_str); /* { dg-bogus "used with arguments" } */
-foo (one_arg); /* { dg-warning "requires at least one" } */
+foo (one_arg); /* { dg-bogus "requires at least one" } */
sys_foo (one_arg); /* { dg-bogus "requires at least one" } */
--- gcc/testsuite/gcc.dg/cpp/macsyntx2.c.jj 2017-11-14 09:18:31.248145232 +0100
+++ gcc/testsuite/gcc.dg/cpp/macsyntx2.c 2017-11-14 09:21:07.675204306 +0100
@@ -0,0 +1,72 @@
+/* Copyright (C) 2000-2017 Free Software Foundation, Inc. */
+
+/* { dg-do preprocess } */
+/* { dg-options "-pedantic -std=c99" } */
+
+/* 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 behavior.
+ 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 "may not appear" } */
+#define foo(..., X) /* { dg-error "missing" } */
+#define foo \
+__VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */
+#define goo(__VA_ARGS__) /* { dg-warning "__VA_ARGS__" } */
+#define hoo(...) __VA_ARGS__ /* OK. */
+#define __VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */
+__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 "passed 1" } */
+one() /* OK. */
+one(ichi) /* OK. */
+one(ichi\
+, ni) /* { dg-error "passed 2" } */
+two(ichi) /* { dg-error "requires 2" } */
+var0() /* OK. */
+var0(ichi) /* OK. */
+var1() /* { dg-warning "requires at least one" } */
+var1(ichi) /* { dg-warning "requires at least one" } */
+var1(ichi, ni) /* OK. */
+
+/* This tests two 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,) /* OK. */
+rest(ichi) /* { dg-warning "requires at least one" } */
+#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 argument" } */
--- gcc/testsuite/gcc.dg/cpp/sysmac3.c.jj 2017-11-14 09:14:20.945250987 +0100
+++ gcc/testsuite/gcc.dg/cpp/sysmac3.c 2017-11-14 09:17:34.787845791 +0100
@@ -0,0 +1,26 @@
+/* Copyright (C) 2001-2017 Free Software Foundation, Inc. */
+
+/* { dg-do preprocess } */
+/* { dg-options "-std=c99 -pedantic -Wtraditional -ftrack-macro-expansion=0" } */
+
+/* Tests diagnostics are suppressed for some macros defined in system
+ headers. */
+
+/* Source: Neil Booth, 15 Jan 2001. */
+
+#include "sysmac3.h"
+
+#define uint 1U
+#define str(x) x
+#define foo(x, y...) bar(x, y) /* { dg-warning "named variadic macros" } */
+
+#if uint /* { dg-warning "traditional C rejects" } */
+#endif
+#if sys_uint /* { dg-bogus "traditional C rejects" } */
+#endif
+
+(str); /* { dg-warning "used with arguments" } */
+(sys_str); /* { dg-bogus "used with arguments" } */
+
+foo (one_arg); /* { dg-warning "requires at least one" } */
+sys_foo (one_arg); /* { dg-bogus "requires at least one" } */
--- gcc/testsuite/gcc.dg/cpp/sysmac3.h.jj 2017-11-14 09:16:52.313372813 +0100
+++ gcc/testsuite/gcc.dg/cpp/sysmac3.h 2017-11-14 09:17:01.947253276 +0100
@@ -0,0 +1,10 @@
+/* Indented to avoid "suggest hiding ..." warnings. */
+ #pragma GCC system_header
+
+#define sys_uint 1U
+#define sys_str(x) x
+#define sys_foo(x, y...) bar (x, y)
+
+#define sys_uint 1U
+#define sys_fl 1.0f
+#define sys_ld 1.0L
Jakub