public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99841] New: (temporary) refs
@ 2021-03-30 19:38 g.peterhoff@t-online.de
  2021-03-30 19:49 ` [Bug c++/99841] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: g.peterhoff@t-online.de @ 2021-03-30 19:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99841
           Summary: (temporary) refs
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: g.peterhoff@t-online.de
  Target Milestone: ---

please see https://godbolt.org/z/Ez1K7eofr
gcc gives different (false?) results than clang/icc. If you set O0 or remove
O-option gives same results.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/99841] (temporary) refs
  2021-03-30 19:38 [Bug c++/99841] New: (temporary) refs g.peterhoff@t-online.de
@ 2021-03-30 19:49 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-03-30 19:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The question is:
mm_pair_t<type>   m{type(1), type(2)};

I think GCC is correct here, type(1) is a temp and it does not bind to a field
directly, it goes through a constructure and therefor the temp goes away right
after the statement is done.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/99841] (temporary) refs
  2021-03-30 19:38 [Bug c++/99841] New: (temporary) refs 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
  2 siblings, 0 replies; 4+ messages in thread
From: g.peterhoff@t-online.de @ 2021-03-30 20:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from g.peterhoff@t-online.de ---
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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/99841] (temporary) refs
  2021-03-30 19:38 [Bug c++/99841] New: (temporary) refs 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
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-03-30 20:09 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-30 20:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-30 19:38 [Bug c++/99841] New: (temporary) refs 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 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).