https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126238
Bug ID: 126238
Summary: Diagnose unused macro parameters
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: preprocessor
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
Would it be possible to add a -Wcpp-unused-parameter diagnostic to diagnose
unused macro parameters?
It would would help catch mistakes like this:
alx@devuan:~/tmp$ cat streq.c
#include <stdio.h>
#include <string.h>
#define streq(a, b) (strcmp(a, a) == 0)
int
main(void)
{
if (streq("foo", "bar"))
puts("huh!");
}
alx@devuan:~/tmp$ gcc -Wall -Wextra streq.c
alx@devuan:~/tmp$ ./a.out
huh!
Of course, it should not be in -Wextra, since many existing programs would
trigger it, in code like this:
#if ...
#define foo(x) bar(x)
#else
#define foo(x)
#endif
But a program that doesn't do this would benefit from such a diagnostic.
Moreover, a program intending to adopt this diagnostic could turn code like the
above into code that doesn't specify the unused parameters explicitly:
#if ...
#define foo(x) bar(x)
#else
#define foo(...)
#endif
(The varying arguments should not be diagnosed unsed this diagnostic, precisely
for this reason.)