Author: Aaron Ballman Date: 2021-10-09T08:20:20-04:00 New Revision: af971365a2a8b0d982814c0652bb86844fd19cda
URL: https://github.com/llvm/llvm-project/commit/af971365a2a8b0d982814c0652bb86844fd19cda DIFF: https://github.com/llvm/llvm-project/commit/af971365a2a8b0d982814c0652bb86844fd19cda.diff LOG: 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. Added: clang/test/Preprocessor/empty_va_arg.cpp Modified: clang/include/clang/Basic/DiagnosticLexKinds.td clang/lib/Lex/PPMacroExpansion.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index 763b7b0086369..7fbf19ed6cb3f 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -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< diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 136f61ab9a507..7b5232d462749 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -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(); } diff --git a/clang/test/Preprocessor/empty_va_arg.cpp b/clang/test/Preprocessor/empty_va_arg.cpp new file mode 100644 index 0000000000000..2ee431f6bde83 --- /dev/null +++ b/clang/test/Preprocessor/empty_va_arg.cpp @@ -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}} +} + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits