diff options
author | Joseph Myers <joseph@codesourcery.com> | 2022-12-07 19:18:06 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2022-12-07 19:18:06 +0000 |
commit | ce53cf7b61ea6bce05570e2fd1f8c10eee308ab0 (patch) | |
tree | d347aafe958f5980ac1294dd4d40d8a33041b5b0 /gcc | |
parent | eb9491baf5a5672888809f8b5932a99d91804a52 (diff) | |
download | gcc-ce53cf7b61ea6bce05570e2fd1f8c10eee308ab0.zip gcc-ce53cf7b61ea6bce05570e2fd1f8c10eee308ab0.tar.gz gcc-ce53cf7b61ea6bce05570e2fd1f8c10eee308ab0.tar.bz2 |
preprocessor: Enable __VA_OPT__ for C2x
C2x supports __VA_OPT__, so adjust libcpp not to pedwarn for uses of
it (or of not passing any variable arguments to a variable-arguments
macro) in standard C2x mode.
I didn't try to duplicate existing tests for the details of the
feature, just verified -pedantic-errors handling is as expected. And
there's a reasonable argument (bug 98859) that __VA_OPT__ shouldn't be
diagnosed in older standard modes at all (as opposed to not passing
any variable arguments to a variable-arguments macro, for which older
versions of the C standard require a diagnostic as a constraint
violation); that argument applies to C as much as to C++, but I
haven't made any changes in that regard.
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
libcpp/
* init.cc (lang_defaults): Enable va_opt for STDC2X.
* lex.cc (maybe_va_opt_error): Adjust diagnostic message for C.
* macro.cc (_cpp_arguments_ok): Update comment.
gcc/testsuite/
* gcc.dg/cpp/c11-vararg-1.c, gcc.dg/cpp/c2x-va-opt-1.c: New tests.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/c11-vararg-1.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/c2x-va-opt-1.c | 11 |
2 files changed, 20 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/cpp/c11-vararg-1.c b/gcc/testsuite/gcc.dg/cpp/c11-vararg-1.c new file mode 100644 index 0000000..6b1bc38 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/c11-vararg-1.c @@ -0,0 +1,9 @@ +/* Test error in C11 for no arguments passed for variable arguments to a + macro. */ +/* { dg-do preprocess } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#define M(X, ...) X + +M (x); /* { dg-error "requires at least one argument" } */ +M (x, y); diff --git a/gcc/testsuite/gcc.dg/cpp/c2x-va-opt-1.c b/gcc/testsuite/gcc.dg/cpp/c2x-va-opt-1.c new file mode 100644 index 0000000..bd438f7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/c2x-va-opt-1.c @@ -0,0 +1,11 @@ +/* Test __VA_OPT__ and no "..." arguments in a call to a variable-arguments + macro accepted for C2X. */ +/* { dg-do preprocess } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +#define CALL(F, ...) F (7 __VA_OPT__(,) __VA_ARGS__) +#define M(X, ...) X + +CALL (a); +CALL (b, 1); +M (x); |