Skip to content
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

clang++-19 -std=gnu++14 -Wc++20-extensions wrongly warns about GNU variadic macro extension #109677

Open
jinkama-san opened this issue Sep 23, 2024 · 4 comments
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@jinkama-san
Copy link

Hi,

for simple code like

#ifdef DEBUG
# define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
# define DBG(fmt, ...)
#endif
#include <stdio.h>
int main()
{
        DBG("Test\n");
}

compiled with clang++-19 -std=gnu++14 test-variadic-macro.cpp -Wc++20-extensions now this incorrect (for C++14 with GNU extensions) warning shows:

test-variadic-macro.cpp:11:14: warning: passing no argument for the '...' parameter of a variadic macro is a C++20 extension [-Wc++20-extensions]
   11 |         DBG("Test\n");
      |                     ^
test-variadic-macro.cpp:4:10: note: macro 'DBG' defined here
    4 | # define DBG(fmt, ...)
      |          ^
1 warning generated.

This breaks a lot of code in release mode compiles. Also adding -Wno-gnu-zero-variadic-macro-arguments after -Wc++20-extensions doesn't help here. All earlier clang versions I tested including clang-18.1.8 got this right and didn't warn.
Maybe related to issue #76375

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Sep 23, 2024
@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed clang Clang issues not falling into any other category labels Sep 23, 2024
@shafik
Copy link
Collaborator

shafik commented Sep 23, 2024

Look like @Sirraide added this in 5231005

The warning looks correct but maybe we need a way to suppress it.

CC @erichkeane

@erichkeane
Copy link
Collaborator

Also adding -Wno-gnu-zero-variadic-macro-arguments after -Wc++20-extensions doesn't help here.

This is likely the bug here, the warning is correct. Its a GNU extension but it is also a C++20 extension. But the fact that we're not able to disable it with its flag if the higher-level flag is enabled is problematic.

@Sirraide
Copy link
Member

Look like @Sirraide added this in 5231005

Iirc the warning was already there before, and I just changed it to allow it for C23 or sth like that, but that was a while ago, so I’m not 100% sure anymore.

@jinkama-san
Copy link
Author

Or maybe, regardless of any warning options, suppress the warning always if none of the named arguments are actually used?
For macros there is never (AFAICT) a warning when a named argument is not used, so a warning after an unused named argument doesn't make much sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

No branches or pull requests

5 participants