Skip to content

Define a diagnostic group for missing variadic macro arguments #116855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,13 @@ def : DiagGroup<"c++1z-compat-mangling", [CXX17CompatMangling]>;
// Name of this warning in GCC.
def NoexceptType : DiagGroup<"noexcept-type", [CXX17CompatMangling]>;

def VariadicMacroArgumentsOmitted : DiagGroup<"variadic-macro-arguments-omitted">;

// Warnings for C code which is not compatible with previous C standards.
def CPre11Compat : DiagGroup<"pre-c11-compat">;
def CPre11CompatPedantic : DiagGroup<"pre-c11-compat-pedantic",
[CPre11Compat]>;
def CPre23Compat : DiagGroup<"pre-c23-compat">;
def CPre23Compat : DiagGroup<"pre-c23-compat", [VariadicMacroArgumentsOmitted]>;
def CPre23CompatPedantic : DiagGroup<"pre-c23-compat-pedantic",
[CPre23Compat]>;
def : DiagGroup<"pre-c2x-compat", [CPre23Compat]>;
Expand Down Expand Up @@ -901,7 +903,7 @@ def VolatileRegisterVar : DiagGroup<"volatile-register-var">;
def Visibility : DiagGroup<"visibility">;
def ZeroLengthArray : DiagGroup<"zero-length-array">;
def GNUZeroLineDirective : DiagGroup<"gnu-zero-line-directive">;
def GNUZeroVariadicMacroArguments : DiagGroup<"gnu-zero-variadic-macro-arguments">;
def GNUZeroVariadicMacroArguments : DiagGroup<"gnu-zero-variadic-macro-arguments", [VariadicMacroArgumentsOmitted]>;
def MisleadingIndentation : DiagGroup<"misleading-indentation">;
def PtrAuthNullPointers : DiagGroup<"ptrauth-null-pointers">;

Expand Down Expand Up @@ -1194,7 +1196,7 @@ def CXX17 : DiagGroup<"c++17-extensions", [CXX17Attrs]>;

// A warning group for warnings about using C++20 features as extensions in
// earlier C++ versions.
def CXX20 : DiagGroup<"c++20-extensions", [CXX20Designator, CXX20Attrs]>;
def CXX20 : DiagGroup<"c++20-extensions", [CXX20Designator, CXX20Attrs, VariadicMacroArgumentsOmitted]>;

// A warning group for warnings about using C++23 features as extensions in
// earlier C++ versions.
Expand All @@ -1221,7 +1223,7 @@ def C11 : DiagGroup<"c11-extensions">;
def C99 : DiagGroup<"c99-extensions", [C99Designator]>;

// A warning group for warnings about using C23 features as extensions.
def C23 : DiagGroup<"c23-extensions">;
def C23 : DiagGroup<"c23-extensions", [VariadicMacroArgumentsOmitted]>;

def : DiagGroup<"c2x-extensions", [C23]>;

Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/Basic/DiagnosticLexKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,14 @@ def ext_embedded_directive : Extension<
InGroup<DiagGroup<"embedded-directive">>;
def ext_c_missing_varargs_arg : Extension<
"passing no argument for the '...' parameter of a variadic macro is "
"a C23 extension">, InGroup<C23>;
"a C23 extension">, InGroup<VariadicMacroArgumentsOmitted>;
def ext_cxx_missing_varargs_arg : Extension<
"passing no argument for the '...' parameter of a variadic macro is "
"a C++20 extension">, InGroup<CXX20>;
"a C++20 extension">, InGroup<VariadicMacroArgumentsOmitted>;
def warn_c17_compat_missing_varargs_arg : Warning<
"passing no argument for the '...' parameter of a variadic macro is "
"incompatible with C standards before C23">,
InGroup<CPre23Compat>, DefaultIgnore;
InGroup<VariadicMacroArgumentsOmitted>, DefaultIgnore;
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">,
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Lexer/gnu-flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@


#if ALL || ZEROARGS
// expected-warning@+9 {{passing no argument for the '...' parameter of a variadic macro is a C23 extension}}
// expected-note@+4 {{macro 'efoo' defined here}}
// expected-warning@+3 {{token pasting of ',' and __VA_ARGS__ is a GNU extension}}
#endif

Expand Down
24 changes: 19 additions & 5 deletions clang/test/Preprocessor/macro_fn.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
/* RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -verify
*/
// RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -Wno-gnu-zero-variadic-macro-arguments -verify -DOMIT_VARIADIC_MACRO_ARGS -DVARIADIC_MACRO_ARGS_REMOVE_COMMA
// RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -Wno-variadic-macro-arguments-omitted -verify -DOMIT_VARIADIC_MACRO_ARGS
/* PR3937 */
#define zero() 0 /* expected-note 2 {{defined here}} */
#define one(x) 0 /* expected-note 2 {{defined here}} */
#define two(x, y) 0 /* expected-note 4 {{defined here}} */
#define zero_dot(...) 0 /* expected-warning {{variadic macros are a C99 feature}} */
#define one_dot(x, ...) 0 /* expected-warning {{variadic macros are a C99 feature}} expected-note 2{{macro 'one_dot' defined here}} */
#define one_dot(x, ...) 0 /* expected-warning {{variadic macros are a C99 feature}} */

#ifndef OMIT_VARIADIC_MACRO_ARGS
/* expected-note@-3 2{{macro 'one_dot' defined here}} */
#endif

zero()
zero(1); /* expected-error {{too many arguments provided to function-like macro invocation}} */
Expand Down Expand Up @@ -37,16 +43,24 @@ e(x)
e()

zero_dot()
one_dot(x) /* empty ... argument: expected-warning {{passing no argument for the '...' parameter of a variadic macro is a C23 extension}} */
one_dot() /* empty first argument, elided ...: expected-warning {{passing no argument for the '...' parameter of a variadic macro is a C23 extension}} */
one_dot(x) /* empty ... argument */
one_dot() /* empty first argument, elided ... */

#ifndef OMIT_VARIADIC_MACRO_ARGS
/* expected-warning@-4 {{passing no argument for the '...' parameter of a variadic macro is a C23 extension}} */
/* expected-warning@-4 {{passing no argument for the '...' parameter of a variadic macro is a C23 extension}} */
#endif

/* Crash with function-like macro test at end of directive. */
#define E() (i == 0)
#if E
#endif


#define NSAssert(condition, desc, ...) /* expected-warning {{variadic macros are a C99 feature}} */ \
SomeComplicatedStuff((desc), ##__VA_ARGS__) /* expected-warning {{token pasting of ',' and __VA_ARGS__ is a GNU extension}} */
SomeComplicatedStuff((desc), ##__VA_ARGS__)

#ifndef VARIADIC_MACRO_ARGS_REMOVE_COMMA
/* expected-warning@-3 {{token pasting of ',' and __VA_ARGS__ is a GNU extension}} */
#endif

NSAssert(somecond, somedesc)
Loading