mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-25 06:40:18 +00:00
Fix a diagnoses-valid in C++20 with variadic macros
C++20 and later allow you to pass no argument for the ... parameter in a variadic macro, whereas earlier language modes and C disallow it. We no longer diagnose in C++20 and later modes. This fixes PR51609.
This commit is contained in:
parent
a1f0f847ff
commit
af971365a2
@ -412,6 +412,10 @@ def ext_embedded_directive : Extension<
|
||||
def ext_missing_varargs_arg : Extension<
|
||||
"must specify at least one argument for '...' parameter of variadic macro">,
|
||||
InGroup<GNUZeroVariadicMacroArguments>;
|
||||
def warn_cxx17_compat_missing_varargs_arg : Warning<
|
||||
"passing no argument for the '...' parameter of a variadic macro is "
|
||||
"incompatible with C++ standards before C++20">,
|
||||
InGroup<CXXPre20Compat>, DefaultIgnore;
|
||||
def ext_empty_fnmacro_arg : Extension<
|
||||
"empty macro arguments are a C99 feature">, InGroup<C99>;
|
||||
def warn_cxx98_compat_empty_fnmacro_arg : Warning<
|
||||
|
@ -988,7 +988,11 @@ MacroArgs *Preprocessor::ReadMacroCallArgumentList(Token &MacroName,
|
||||
// If the macro contains the comma pasting extension, the diagnostic
|
||||
// is suppressed; we know we'll get another diagnostic later.
|
||||
if (!MI->hasCommaPasting()) {
|
||||
Diag(Tok, diag::ext_missing_varargs_arg);
|
||||
// C++20 allows this construct, but standards before C++20 and all C
|
||||
// standards do not allow the construct (we allow it as an extension).
|
||||
Diag(Tok, getLangOpts().CPlusPlus20
|
||||
? diag::warn_cxx17_compat_missing_varargs_arg
|
||||
: diag::ext_missing_varargs_arg);
|
||||
Diag(MI->getDefinitionLoc(), diag::note_macro_here)
|
||||
<< MacroName.getIdentifierInfo();
|
||||
}
|
||||
|
12
clang/test/Preprocessor/empty_va_arg.cpp
Normal file
12
clang/test/Preprocessor/empty_va_arg.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
// RUN: %clang_cc1 -Eonly -std=c++17 -pedantic -verify %s
|
||||
// RUN: %clang_cc1 -Eonly -std=c17 -pedantic -verify -x c %s
|
||||
// RUN: %clang_cc1 -Eonly -std=c++20 -pedantic -Wpre-c++20-compat -verify=compat %s
|
||||
|
||||
#define FOO(x, ...) // expected-note {{macro 'FOO' defined here}} \
|
||||
// compat-note {{macro 'FOO' defined here}}
|
||||
|
||||
int main() {
|
||||
FOO(42) // expected-warning {{must specify at least one argument for '...' parameter of variadic macro}} \
|
||||
// compat-warning {{passing no argument for the '...' parameter of a variadic macro is incompatible with C++ standards before C++20}}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user