public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102704] New: NRVO for throw expression
@ 2021-10-12 13:39 vanyacpp at gmail dot com
  2021-10-13  6:22 ` [Bug c++/102704] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: vanyacpp at gmail dot com @ 2021-10-12 13:39 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102704
           Summary: NRVO for throw expression
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vanyacpp at gmail dot com
  Target Milestone: ---

Consider this code:

struct mytype
{
    mytype();
    mytype(mytype const&);
    mytype(mytype&&);
};

void test()
{
    mytype e;
    throw e;
}

Currently for function test() GCC generates the following sequence of calls
(pseudocode):

    char e[sizeof(mytype)];
    mytype_default_ctor(e);
    p = __cxa_allocate_exception();
    mytype_move_ctor(p, e);
    __cxa_throw(p);

I believe a trick similar to NRVO for returns can be made here. When a variable
meets NRVO criteria, compiler can remove the local variable and replace it with
a storage allocated by __cxa_allocate_exception. Here what I believe can be
generated:

    p = __cxa_allocate_exception();
    mytype_default_ctor(p);
    __cxa_throw(p);

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

end of thread, other threads:[~2021-10-13  8:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12 13:39 [Bug c++/102704] New: NRVO for throw expression vanyacpp at gmail dot com
2021-10-13  6:22 ` [Bug c++/102704] " rguenth at gcc dot gnu.org
2021-10-13  8:43 ` redi at gcc dot gnu.org
2021-10-13  8:47 ` 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).