Consider this C code: typedef struct { int x[1]; } foo; foo f(void); int g(void) { int *p = f().x; return *p; } The g() function is always UB, since the return value of f() has temporary lifetime, so doing "return *p;" is dereferencing a pointer to an object whose lifetime has ended. (This is the case both before and after C11's change to temporary lifetime.) Since it's obvious at compile time that p can never be used safely, we should have a warning for it, similar to how we have -Wreturn-local-addr to catch mistakes like this function: int *h(void) { int x; return &x; }
Confirmed as an enhancement request for the front end. The Gimplifier introduces a local variable for the return value so the problem is no longer detectable: $ cat pr101358.c && /build/gcc-master/gcc/xgcc -B /build/gcc-master/gcc -S -Wall -fdump-tree-original=/dev/stdout -fdump-tree-gimple=/dev/stdout pr101358.c typedef struct { int x[1]; } foo; foo f(void); int g(void) { int *p = f().x; return *p; } ;; Function g (null) ;; enabled by -tree-original { int * p = (int *) &f ().x; int * p = (int *) &f ().x; return *p; } int g () { struct { int x[1]; } D.1952; int D.1953; int * p; D.1952 = f (); p = &D.1952.x; D.1953 = *p; return D.1953; }