https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104690

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #4)
> Couldn't the C front end insert a trap at the end of the function for -O0
> compilations? That would at least diagnose this for unoptimized builds.
> That's what G++ does now.

We can't.  Because
int foo (int x) { if (x) return 42; }
...
extern int foo (int);
void bar (void)
{
  foo (0);
}
is well defined in C (but not in C++).
extern int foo (int);
int v;
void baz (void)
{
  if (foo (0))
    ++v;
}
is UB though (actually using the result).  But I think it is fuzzy what counts
as actually using the result.

Reply via email to