In the following C program, functions f
, g
, and h
are essentially identical, however clang-tidy says that parameter p
can be pointer-to-const in g
and h
(but not in f
). My understanding is that p
can't be pointer-to-const in any of them. Is that a false positive?
struct S { int *p; };
extern void x(struct S *s);
void f(int *p)
{
struct S s;
s.p = p;
x(&s);
}
void g(int *p)
{
struct S s = { .p = p };
x(&s);
}
void h(int *p)
{
struct S s = { p };
x(&s);
}
int main()
{
int a = 0;
f(&a);
g(&a);
h(&a);
}
Output from clang-tidy:
$ clang-tidy --checks=* a.c
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "a.c"
No compilation database found in /home/wolfram or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
2 warnings generated.
/home/wolfram/a.c:14:13: warning: pointer parameter 'p' can be pointer to const [readability-non-const-parameter]
void g(int *p)
^
const
/home/wolfram/a.c:20:13: warning: pointer parameter 'p' can be pointer to const [readability-non-const-parameter]
void h(int *p)
^
const
Tried with clang-tidy versions 10 and 11.
The following may be related: https://bugs.llvm.org/show_bug.cgi?id=41393