Questions tagged [rvo]

C++ copy-elision of return-values

(Named) Return Value Optimization is an exception to the as-if rule governing optimizations C++ implementations may perform.

It allows elliding a copy of the (named) return-value, if it is a local variable or a temporary.

See .

143 questions
0
votes
1 answer

Why the error C2248 when the copy constructor is private in the code below?

This code emits error C2248: 'A::A' : cannot access private member declared in class 'A' in VS2010, although RVO doesn't need a copy constructor. To prove this, just turn public the declaration A(const A&); below, and the code will execute without a…
Belloc
  • 6,318
  • 3
  • 22
  • 52
-1
votes
1 answer

can't find a way to make garanteed return value optimization work

Why the clang says call to deleted constructor of 'Block::Self' (aka 'Block') in the call of Block::a1() when I delete the move constructor? c++17 clang version 9.0.0 (tags/RELEASE_900/final) Target: x86_64-pc-linux-gnu Thread…
Mard
  • 38
  • 1
  • 4
-1
votes
1 answer

Return value optimization with std::pair

I am currently quite puzzled with C++17`s guaranteed RVO and its implications. I understand that for NRVO to kick in, I need to make sure that to return one and the same instance of an object through all possible return path of the function and…
CD86
  • 979
  • 10
  • 27
-1
votes
2 answers

Why does not apply RVO in this code

There is a Complex class with constructor which prints a message for RVO. I have tested Complex's operator+ method in gtest. If RVO is occurred, prints "Complex!!" messages for 3 times. But There are "Complex!!" messages for 5 times. RVO is not…
appchemist
  • 345
  • 2
  • 3
  • 11
-1
votes
1 answer

Strange result when implementing multiple return statements c++

I have a very strange problem with my application. I am using STM Development board NUCLEO-F411RE with the MBED Online IDE. My function myObj() returns an object; a value of the returned object is printed to the LCD. I seem to identify some problem,…
-1
votes
1 answer

munmap_chunk invalid pointer when operator and then destroctor called

I faced with a weird situation while writing my C++ code. Inside my code, I have a matrix object called C. C would be equal to sum of matrix A and B. The value of A+B is calculated through an operator+. When life of C is ended, I face with an…
barej
  • 1,330
  • 3
  • 25
  • 56
-3
votes
1 answer

Will std::move() upon object construction in return statement help or prevent RVO?

Due to widely ranging responses from the community, I am asking this in hopes to debunk implementation-specific responses from stack-overflow users. Which of these is best-practice (offers greatest optimization)? // version 1 MyObject…
Roman
  • 13
  • 3
-4
votes
1 answer

Can libraries with implementation seperated from decalration benefit from RVO/NRVO?

Just as shown in the title, I was writing a static library with a class template and several non-template operator overloads. The class template is defined in a.h, and the functions was defined in a.cc. So I decide to go on to ask whether RVO/NRVO…
JiaHao Xu
  • 2,452
  • 16
  • 31
1 2 3
9
10