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

--- Comment #6 from Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> ---
Thanks, that looks much less noisy! (Assuming godbolt.org has updated already.)
I now see this:

// https://godbolt.org/z/WqT6hs8ed

f3, f7, and f9 now all give -Wuninitialized at -O1 and higher (and
false-negative at -O0). I continue to think that this is a confusing/wrong
diagnostic, even though it does achieve the pragmatic effect of saying "hey
*something* is wrong with this line." I also continue to think that the message
could be marginally improved by spelling out the type of the '<anonymous>'
object it's complaining about. If you're lucky, that's an object of type `int`
(the temporary constructed from `c`). But I honestly don't know if you'll be
lucky; it's unclear to me why GCC is giving the -Wuninitialized message at all,
here.


<source>:15:56: warning: '<anonymous>' is used uninitialized [-Wuninitialized]
   15 | int f3(char c) { const int& x = GetKey().rc(c); return x; } // True
positive
      |                                                        ^
<source>:15:44: note: '<anonymous>' was declared here
   15 | int f3(char c) { const int& x = GetKey().rc(c); return x; } // True
positive
      |                                 ~~~~~~~~~~~^~~

(What happens here is that we convert the value of `char c` to a prvalue int;
materialize that temporary; pass a reference to the temporary to `rc`; `rc`
returns a reference to that same temporary; we bind `x` to that reference; and
then the temporary is destroyed. `x` dangles.)

Reply via email to