https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98549
--- Comment #15 from joseph at codesourcery dot com <joseph at codesourcery dot com> --- On Mon, 18 Jan 2021, segher at gcc dot gnu.org via Gcc-bugs wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98549 > > --- Comment #14 from Segher Boessenkool <segher at gcc dot gnu.org> --- > (In reply to Jakub Jelinek from comment #13) > > For UB at runtime, we can warn, but shouldn't error because the code might > > never be invoked at runtime. > > As far as I can see at least the C standard disagrees with this: > NOTE Possible undefined behavior ranges from ignoring the situation > completely with unpredictable results, to behaving during translation > or program execution in a documented manner characteristic of the > environment (with or without the issuance of a diagnostic message), to > terminating a translation or execution (with the issuance of a > diagnostic message). > > So we are allowed to error. Only if the undefined behavior is a property of the program, or of all possible executions of the program, as opposed to a property of a particular execution of the program. See C90 DR#109. "A conforming implementation must not fail to translate a strictly conforming program simply because *some* possible execution of that program would result in undefined behavior.".