AaronBallman wrote:

> > /cc @SharonXSharon
> 
> thanks for submitting the fix! A noob question, I wonder in general why does 
> clang choose to warn on the invalid formatter instead of erroring out given 
> it'll be undefined behavior for invalid formatter?

Functionally, some kinds of UB are worse than other kinds. For example, if the 
size and alignment are the same between the format specifier and the data, the 
UB could be benign, as with: https://godbolt.org/z/dGbzx3PYW so a warning 
sometimes may be preferable. Other situations are like the one above where C23 
adds `%b`, but the code could be compiled in C17 mode but linked against a 
C23-compatible standard library.

That said, it *might* make sense to make some of the diagnostics a warning 
which default to an error because plenty of forms of UB (especially for things 
like `sprintf`) can be dangerous.

https://github.com/llvm/llvm-project/pull/126694
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to