public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101631] New: gcc permits object reference to object outside of its lifetime during constant evaluation
@ 2021-07-26 18:46 fsb4000 at yandex dot ru
  2021-07-26 20:45 ` [Bug c++/101631] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: fsb4000 at yandex dot ru @ 2021-07-26 18:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101631
           Summary: gcc permits object reference to object outside of its
                    lifetime during constant evaluation
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fsb4000 at yandex dot ru
  Target Milestone: ---

Hi.

The bug has come up during the implementation of SSO for constexpr std::string
which can be found here:
https://github.com/microsoft/STL/pull/1735#discussion_r674285711

The issue stems from an obscure
rule(https://eel.is/c++draft/class.union.general#6) that allows switching the
active member of a union by assigning to an element of the array member.
(Obligatory godbolt: https://godbolt.org/z/6qG7v9eYx)

While the usage on line 12 is indeed correct, for std::string we need to go
through char_traits which is imitated by perform_assignment. However, the
lifetime of the subobject buf[5] only starts right before the assignment inside
of perform_assignment, so on line 25 we form an object reference to an object
outside of its lifetime which is ill formed.

gcc should emit an appropriate diagnostic.

Found by: Michael Schellenberger Costa

I hope it helps.

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

end of thread, other threads:[~2023-12-12 18:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-26 18:46 [Bug c++/101631] New: gcc permits object reference to object outside of its lifetime during constant evaluation fsb4000 at yandex dot ru
2021-07-26 20:45 ` [Bug c++/101631] " redi at gcc dot gnu.org
2021-07-27  2:32 ` fsb4000 at yandex dot ru
2021-07-27 11:06 ` rguenth at gcc dot gnu.org
2021-07-27 14:57 ` redi at gcc dot gnu.org
2023-10-20  3:26 ` [Bug c++/101631] gcc allows for the changing of an union active member to be changed via a reference cvs-commit at gcc dot gnu.org
2023-10-25  6:04 ` sjames at gcc dot gnu.org
2023-10-26  0:19 ` nathanieloshead at gmail dot com
2023-10-26 14:58 ` ppalka at gcc dot gnu.org
2023-12-12 18:45 ` ppalka 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).