Skip to content

Commit c8b7ec2

Browse files
authored
Define a diagnostic group for missing variadic macro arguments (#116855)
Make the new diagnostic group a subgroup of the following diagnostic groups: -Wpre-c23-compat -Wgnu-zero-variadic-macro-arguments -Wc++20-extensions -Wc23-extensions This change is needed as 5231005 made it impossible to use -Wno-gnu-zero-variadic-macro-argumentsis to silence the warning. rdar://139234984
1 parent ea6cdb9 commit c8b7ec2

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,13 @@ def : DiagGroup<"c++1z-compat-mangling", [CXX17CompatMangling]>;
294294
// Name of this warning in GCC.
295295
def NoexceptType : DiagGroup<"noexcept-type", [CXX17CompatMangling]>;
296296

297+
def VariadicMacroArgumentsOmitted : DiagGroup<"variadic-macro-arguments-omitted">;
298+
297299
// Warnings for C code which is not compatible with previous C standards.
298300
def CPre11Compat : DiagGroup<"pre-c11-compat">;
299301
def CPre11CompatPedantic : DiagGroup<"pre-c11-compat-pedantic",
300302
[CPre11Compat]>;
301-
def CPre23Compat : DiagGroup<"pre-c23-compat">;
303+
def CPre23Compat : DiagGroup<"pre-c23-compat", [VariadicMacroArgumentsOmitted]>;
302304
def CPre23CompatPedantic : DiagGroup<"pre-c23-compat-pedantic",
303305
[CPre23Compat]>;
304306
def : DiagGroup<"pre-c2x-compat", [CPre23Compat]>;
@@ -906,7 +908,7 @@ def VolatileRegisterVar : DiagGroup<"volatile-register-var">;
906908
def Visibility : DiagGroup<"visibility">;
907909
def ZeroLengthArray : DiagGroup<"zero-length-array">;
908910
def GNUZeroLineDirective : DiagGroup<"gnu-zero-line-directive">;
909-
def GNUZeroVariadicMacroArguments : DiagGroup<"gnu-zero-variadic-macro-arguments">;
911+
def GNUZeroVariadicMacroArguments : DiagGroup<"gnu-zero-variadic-macro-arguments", [VariadicMacroArgumentsOmitted]>;
910912
def MisleadingIndentation : DiagGroup<"misleading-indentation">;
911913
def PtrAuthNullPointers : DiagGroup<"ptrauth-null-pointers">;
912914

@@ -1199,7 +1201,7 @@ def CXX17 : DiagGroup<"c++17-extensions", [CXX17Attrs]>;
11991201

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

12041206
// A warning group for warnings about using C++23 features as extensions in
12051207
// earlier C++ versions.
@@ -1226,7 +1228,7 @@ def C11 : DiagGroup<"c11-extensions">;
12261228
def C99 : DiagGroup<"c99-extensions", [C99Designator]>;
12271229

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

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

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,14 @@ def ext_embedded_directive : Extension<
486486
InGroup<DiagGroup<"embedded-directive">>;
487487
def ext_c_missing_varargs_arg : Extension<
488488
"passing no argument for the '...' parameter of a variadic macro is "
489-
"a C23 extension">, InGroup<C23>;
489+
"a C23 extension">, InGroup<VariadicMacroArgumentsOmitted>;
490490
def ext_cxx_missing_varargs_arg : Extension<
491491
"passing no argument for the '...' parameter of a variadic macro is "
492-
"a C++20 extension">, InGroup<CXX20>;
492+
"a C++20 extension">, InGroup<VariadicMacroArgumentsOmitted>;
493493
def warn_c17_compat_missing_varargs_arg : Warning<
494494
"passing no argument for the '...' parameter of a variadic macro is "
495495
"incompatible with C standards before C23">,
496-
InGroup<CPre23Compat>, DefaultIgnore;
496+
InGroup<VariadicMacroArgumentsOmitted>, DefaultIgnore;
497497
def warn_cxx17_compat_missing_varargs_arg : Warning<
498498
"passing no argument for the '...' parameter of a variadic macro is "
499499
"incompatible with C++ standards before C++20">,

clang/test/Lexer/gnu-flags.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717

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

clang/test/Preprocessor/macro_fn.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
/* RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -verify
22
*/
3+
// RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -Wno-gnu-zero-variadic-macro-arguments -verify -DOMIT_VARIADIC_MACRO_ARGS -DVARIADIC_MACRO_ARGS_REMOVE_COMMA
4+
// RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -Wno-variadic-macro-arguments-omitted -verify -DOMIT_VARIADIC_MACRO_ARGS
35
/* PR3937 */
46
#define zero() 0 /* expected-note 2 {{defined here}} */
57
#define one(x) 0 /* expected-note 2 {{defined here}} */
68
#define two(x, y) 0 /* expected-note 4 {{defined here}} */
79
#define zero_dot(...) 0 /* expected-warning {{variadic macros are a C99 feature}} */
8-
#define one_dot(x, ...) 0 /* expected-warning {{variadic macros are a C99 feature}} expected-note 2{{macro 'one_dot' defined here}} */
10+
#define one_dot(x, ...) 0 /* expected-warning {{variadic macros are a C99 feature}} */
11+
12+
#ifndef OMIT_VARIADIC_MACRO_ARGS
13+
/* expected-note@-3 2{{macro 'one_dot' defined here}} */
14+
#endif
915

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

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

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

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

49-
5059
#define NSAssert(condition, desc, ...) /* expected-warning {{variadic macros are a C99 feature}} */ \
51-
SomeComplicatedStuff((desc), ##__VA_ARGS__) /* expected-warning {{token pasting of ',' and __VA_ARGS__ is a GNU extension}} */
60+
SomeComplicatedStuff((desc), ##__VA_ARGS__)
61+
62+
#ifndef VARIADIC_MACRO_ARGS_REMOVE_COMMA
63+
/* expected-warning@-3 {{token pasting of ',' and __VA_ARGS__ is a GNU extension}} */
64+
#endif
65+
5266
NSAssert(somecond, somedesc)

0 commit comments

Comments
 (0)