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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to g.peterhoff from comment #2)
> That is not the problem. I only made using type = ... and type(x) in the
> ctor calls so that I can test different types. You like to throw that out -
> has no influence.

I think you misunderstood.
Take a look at:
mm_pair_t<type>   m{type(1), type(2)};

there are two temps here created by type(1) and type(2).  The lifetime of those
temps normally end at the end of the statement, unless they are extended due to
the C++ rules of binding the temp to a reference.  In this case they are not
bound to a reference as the reference is not m but rather the constructor
arguments (this is why mm_t works while the others don't).

Adding -W -Wall -Werror to the command line we get the following
warnings/errors:

<source>: In function 'int main()':
<source>:33:24: error: '<anonymous>' is used uninitialized
[-Werror=uninitialized]
   33 |         std::cout << m.first << std::endl;
      |                        ^~~~~
<source>:34:24: error: '<anonymous>' is used uninitialized
[-Werror=uninitialized]
   34 |         std::cout << m.second << std::endl;
      |                        ^~~~~~
<source>:39:35: error: '<anonymous>' is used uninitialized
[-Werror=uninitialized]
   39 |         std::cout << std::get<0>(m) << std::endl;
      |                                   ^
<source>:40:35: error: '<anonymous>' is used uninitialized
[-Werror=uninitialized]
   40 |         std::cout << std::get<1>(m) << std::endl;
      |                                   ^
<source>:45:24: error: '<anonymous>' is used uninitialized
[-Werror=uninitialized]
   45 |         std::cout << m.min << std::endl;
      |                        ^~~
<source>:46:24: error: '<anonymous>' is used uninitialized
[-Werror=uninitialized]
   46 |         std::cout << m.max << std::endl;
      |                        ^~~

----- CUT ----
Which is exactly what you expect when the temp rvalue does not gets its
timeline extended past the end of that statement.

Reply via email to