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] False positive clang-diagnostic-format with long format specifier on Windows #109959

Open
chrchr-github opened this issue Sep 25, 2024 · 0 comments
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer false-positive Warning fires when it should not

Comments

@chrchr-github
Copy link

#include <cstdio>

enum E : unsigned { E0, E1 };

int f(const char* c) {
    E e;
    return sscanf(c, "%lx", &e);
}
.\foo.cpp:7:29: warning: format specifies type 'unsigned long *' but the argument has type 'E *' [clang-diagnostic-format]
    7 |     return sscanf(c, "%lx", &e);
      |                       ~~~   ^~
      |                       %x

The warning goes away if E's base type is unsigned long, but long types are also 32bit on Windows.
There also is no warning for e.g. a typeless enum and %x.
If the warning is (correctly) triggered by a size mismatch, this should be stated in the error message.

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Sep 25, 2024
@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer false-positive Warning fires when it should not and removed clang Clang issues not falling into any other category labels Sep 25, 2024
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 false-positive Warning fires when it should not
Projects
None yet
Development

No branches or pull requests

2 participants