public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58050] New: RVO fails when calling static function through unnamed temporary
@ 2013-08-02  3:08 scovich at gmail dot com
  2013-08-02  7:44 ` [Bug c++/58050] No return value optimization " paolo.carlini at oracle dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: scovich at gmail dot com @ 2013-08-02  3:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58050

            Bug ID: 58050
           Summary: RVO fails when calling static function through unnamed
                    temporary
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: scovich at gmail dot com

Return value optimization is not applied when calling a static member function
via an unnamed temporary (value or pointer, it doesn't matter). Calling the
function directly, or through a named value/pointer, works as expected:

// <<<--- bug.cpp --->>>
extern "C" int puts(char const*);
struct B {
    ~B() { puts("\t~B"); }
};
struct A {
    static B make() { return B(); }
} a;
A *ap() { return &a; }
int main () {
    puts("b1");
    {B b = A::make();}
    puts("b2");
    {B B = a.make();}
    puts("b3");
    {B b = ap()->make();}
    puts("b4");
    {B b = A().make();}
}
// <<<--- end bug.cpp --->>>

Output is (same for both 4.8.1 and 4.6.3):
$ g++ bug.cpp && ./a.out
b1
        ~B
b2
        ~B
b3
        ~B
        ~B
b4
        ~B
        ~B

The workaround is simple enough to apply, if you happen to notice all the extra
object copies being made; I isolated the test case from an app that used 5x
more malloc bandwidth than necessary because a single static function called
the wrong way returned a largish STL object by value.


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

* [Bug c++/58050] No return value optimization when calling static function through unnamed temporary
  2013-08-02  3:08 [Bug c++/58050] New: RVO fails when calling static function through unnamed temporary scovich at gmail dot com
@ 2013-08-02  7:44 ` paolo.carlini at oracle dot com
  2021-06-28 16:32 ` antoshkka at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-02  7:44 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58050

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
           Severity|normal                      |enhancement


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

* [Bug c++/58050] No return value optimization when calling static function through unnamed temporary
  2013-08-02  3:08 [Bug c++/58050] New: RVO fails when calling static function through unnamed temporary scovich at gmail dot com
  2013-08-02  7:44 ` [Bug c++/58050] No return value optimization " paolo.carlini at oracle dot com
@ 2021-06-28 16:32 ` antoshkka at gmail dot com
  2023-06-06 16:02 ` jason at gcc dot gnu.org
  2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: antoshkka at gmail dot com @ 2021-06-28 16:32 UTC (permalink / raw)
  To: gcc-bugs

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

Antony Polukhin <antoshkka at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |antoshkka at gmail dot com

--- Comment #1 from Antony Polukhin <antoshkka at gmail dot com> ---
This was fixed in GCC-10.1 https://godbolt.org/z/b4ohfnK3x

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

* [Bug c++/58050] No return value optimization when calling static function through unnamed temporary
  2013-08-02  3:08 [Bug c++/58050] New: RVO fails when calling static function through unnamed temporary scovich at gmail dot com
  2013-08-02  7:44 ` [Bug c++/58050] No return value optimization " paolo.carlini at oracle dot com
  2021-06-28 16:32 ` antoshkka at gmail dot com
@ 2023-06-06 16:02 ` jason at gcc dot gnu.org
  2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2023-06-06 16:02 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org
   Target Milestone|---                         |10.0
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
Indeed, fixed.

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

* [Bug c++/58050] No return value optimization when calling static function through unnamed temporary
  2013-08-02  3:08 [Bug c++/58050] New: RVO fails when calling static function through unnamed temporary scovich at gmail dot com
                   ` (2 preceding siblings ...)
  2023-06-06 16:02 ` jason at gcc dot gnu.org
@ 2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-07  1:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:4fe84e2a4c0b600d2bc01f171b3b9dd1f4357208

commit r14-1589-g4fe84e2a4c0b600d2bc01f171b3b9dd1f4357208
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jun 6 12:01:23 2023 -0400

    c++: add NRV testcase [PR58050]

    This was fixed in GCC 10.

            PR c++/58050

    gcc/testsuite/ChangeLog:

            * g++.dg/opt/nrv24.C: New test.

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

end of thread, other threads:[~2023-06-07  1:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-02  3:08 [Bug c++/58050] New: RVO fails when calling static function through unnamed temporary scovich at gmail dot com
2013-08-02  7:44 ` [Bug c++/58050] No return value optimization " paolo.carlini at oracle dot com
2021-06-28 16:32 ` antoshkka at gmail dot com
2023-06-06 16:02 ` jason at gcc dot gnu.org
2023-06-07  1:33 ` cvs-commit 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).