Open neldredge opened 3 months ago
...is an implementation of printf
required to perform IO if the string is ""
?
That is, is printf required to be considered a library I/O function if it will perform no actual I/O? Is the interpretation of "I/O function" meant to be effectual (any function in any header is an I/O function if it performs I/O" or is it meant to be "yes we meant <iostream>
and <cstdio>
".
The C++ forward progress rules say that a program has UB unless it eventually does one of a certain list of things, one of which is "make a call to a library I/O function". Certainly
printf
should qualify. However, clang optimizes outprintf("")
and does not treat it as providing forward progress.The following code:
is compiled by
clang -O3
intounreachable
, i.e. no code at all. https://clang.godbolt.org/z/6cP9vxsh7 I believe this is wrong. By the letter of the rule it should be legal, and should actually execute an infinite loop (though it does not need to actually callprintf
, since that is indeed a no-op).Related is #62057, where a similar thing happens when the loop contains an atomic load with no effect, and #96702, for atomic fences.