public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/99841] (temporary) refs
Date: Tue, 30 Mar 2021 20:09:31 +0000	[thread overview]
Message-ID: <bug-99841-4-YAJ7qctVJf@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-99841-4@http.gcc.gnu.org/bugzilla/>

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.

      parent reply	other threads:[~2021-03-30 20:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30 19:38 [Bug c++/99841] New: " g.peterhoff@t-online.de
2021-03-30 19:49 ` [Bug c++/99841] " pinskia at gcc dot gnu.org
2021-03-30 20:00 ` g.peterhoff@t-online.de
2021-03-30 20:09 ` pinskia at gcc dot gnu.org [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-99841-4-YAJ7qctVJf@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).