[Issue 21605] Instead of giving error on printf format mismatch, correct it

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Feb 3 10:36:13 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21605

Dennis <dkorpel at live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dkorpel at live.nl

--- Comment #2 from Dennis <dkorpel at live.nl> ---
I would not want to rely on compiler magic to rewrite a faulty format string
into a 
correct one. You even said yourself:

> I used to write macros in C named "printf" that would muck about with the arguments, 
> add some logic, then call the real printf. After a few years I got tired of them, 
> and put them in a bag with some rocks and threw it in the swamp.

https://forum.dlang.org/post/rv5idj$1all$1@digitalmars.com

> It's kinda trivially obvious that someone can write their own functions to do 
> things, but pretending it is printf by naming it printf just puts a layer of 
> confusion in for the reader. printf is so ubiquitous that it brings 
> expectations when saying printf can be called that printf is actually being 
> called, rather than some intermediary one must write oneself.

https://forum.dlang.org/post/rv5fln$14n2$1@digitalmars.com

This is essentially such an intermediary function, only it's always inlined 
and implemented in the compiler. Ways this could backfire are:

- The code is compiled with an older D compiler that doesn't apply the fix
- printf arguments are copied to a third party 'my_printf' function that is 
  not annotated with pragma(printf)
- Someone unaware of D's printf magic translates D code to C 

Proposing the correct format specifier for the type (instead of only the
correct 
type for the format specifier) in the error message seems like a good idea.

--


More information about the Digitalmars-d-bugs mailing list