Created
December 2, 2008 01:02
-
-
Save yang/30927 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class c { | |
public: | |
c() : c_(NULL) { cout << "c(" << c_ << ") this=" << this << endl; } | |
c(const c& c) : c_(&c) { cout << "c(" << c_ << ") this=" << this << endl; } | |
~c() { cout << "~c(" << c_ << ") this=" << this << endl; } | |
int f() { cout << "c(" << c_ << ").f() this=" << this << endl; return 0; } | |
private: | |
const c* c_; | |
}; | |
template<typename T> void nop(const T &x) { cout << "nop()" << endl; } | |
int main() { | |
nop(c(c()).f()); | |
return 0; | |
} | |
/* | |
I get: | |
c(0) this=0x7fff13f56120 | |
c(0).f() this=0x7fff13f56120 | |
nop() | |
~c(0) this=0x7fff13f56120 | |
I'm expecting (where .... are non-zero values): | |
c(0) this=... | |
c(...) this=... | |
c(...).f() this=... | |
nop() | |
~c(...) this=... | |
~c(0) this=... | |
Some people have suggested that RVO is happening. However: | |
- would RVO take precedence over program semantics? | |
- I didn't use optimization flags (default is -O0) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment