[clang] [clang-tools-extra] [compiler-rt] [lldb] [Clang] [Sema] Make `-Wincompatible-pointer-types` an error by default (PR #157364)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 17 07:27:20 PDT 2025
erichkeane wrote:
> This diagnostic fires in the following code - https://gcc.godbolt.org/z/G6sYcTnWc:
>
> ```
> extern void f(struct stat*);
> #include <sys/stat.h>
> void g() {
> struct stat s;
> f(&s);
> }
> ```
>
> ```
> <source>:1:22: warning: declaration of 'struct stat' will not be visible outside of this function [-Wvisibility]
> 1 | extern void f(struct stat*);
> | ^
> <source>:5:7: error: incompatible pointer types passing 'struct stat *' to parameter of type 'struct stat *' [-Wincompatible-pointer-types]
> 5 | f(&s);
> | ^~
> <source>:1:27: note: passing argument to parameter here
> 1 | extern void f(struct stat*);
> | ^
> ```
>
> Is this expected?
Yes. The prototype of `f` is using a `locally` defined struct (see the `Wvisibility` diagnostic). So that type is ONLY visible on line 1.
The version of `stat` from the `stat` header is a DIFFERENT one of the same name. In reality, we chould probably identify when the names are the same and try to point via a note WHERE the first declaration of each type is (which might give a better hint here), but these are different types.
IF this is your code, I'd suggest doing a forward-declaration of `struct stat` outside of a function prototype.
https://github.com/llvm/llvm-project/pull/157364
More information about the cfe-commits
mailing list