[clang] [-Wunsafe-buffer-usage] Add check for custom printf/scanf functions (PR #173096)

Ziqing Luo via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 6 13:08:21 PST 2026


ziqingluo-90 wrote:

> Here's the reduced code:
> 
> ```
> enum errc { not_a_directory };
> namespace detail {
> struct ErrorHandler {
>   ErrorHandler(char *, int *, int *, int *);
>   __attribute__((__format__(__printf__, 3, 4))) void report(errc, char *);
> };
> } // namespace detail
> using detail::ErrorHandler;
> int __create_directory_ec, __create_directory_p, __create_directory_attributes;
> void __create_directory() {
>   ErrorHandler err("", &__create_directory_ec, &__create_directory_p,
>                    &__create_directory_attributes);
>   err.report(not_a_directory, "");
> }
> ```
> 
> repro command: `clang++ -Wunsafe-buffer-usage crash.cpp`

Isn't `__attribute__((__format__(__printf__, 3, 4))) void report(errc, char *);` a compilation error by default?

https://github.com/llvm/llvm-project/pull/173096


More information about the cfe-commits mailing list