public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kenton at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/53637] New: NRVO not applied in branches when it could be
Date: Mon, 11 Jun 2012 19:29:00 -0000	[thread overview]
Message-ID: <bug-53637-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             Bug #: 53637
           Summary: NRVO not applied in branches when it could be
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: kenton@google.com


In the example below it should be possible to apply NRVO.  This situation is
similar to, but more complicated than, the one reported in PR51571.

Note that while this is "just a missed optimization", NRVO can affect the way
interfaces are designed, so aggressively covering all possible cases seems more
important than with most optimizations.

$ cat nrvo.cc 
class Foo {
public:
  Foo() {}

  // Declare but don't define so that if NRVO doesn't kick in we
  // get a linker error.
  Foo(const Foo& other);
};

Foo bar(int i) {
  if (i > 1) {
    Foo result;
    return result;
  } else {
    Foo result;
    return result;
  }
}

int main(int argc, char* argv[]) {
  Foo f = bar(argc);
}

$ g++-4.7 -O2 nrvo.cc
/tmp/ccRlHce1.o: In function `bar(int)':
nrvo.cc:(.text+0xe): undefined reference to `Foo::Foo(Foo const&)'
collect2: error: ld returned 1 exit status
$ g++-4.7 --version
g++-4.7 (Ubuntu/Linaro 4.7.0-7ubuntu3) 4.7.0
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


             reply	other threads:[~2012-06-11 19:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-11 19:29 kenton at google dot com [this message]
2015-02-04 22:28 ` [Bug c++/53637] " marc at kdab dot com
2015-02-04 22:51 ` [Bug c++/53637] NRVO not applied where there are two different variables involved pinskia at gcc dot gnu.org
2021-12-17  4:45 ` pinskia at gcc dot gnu.org
2023-06-07 22:08 ` cvs-commit at gcc dot gnu.org

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-53637-4@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).