Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
compile c++ gcc online
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#include <cstdio> #include <atomic> #include <type_traits> #include <string> #include <exception> class RVO; static thread_local RVO* rvo_id; // pass hidden data along with this TLS class RVO { int id; public: RVO(int i) : id(i) {printf("%d: I am in constructor. %s\n", id, rvo_id==this?"WORKS!!!":"");} RVO (RVO&& c_RVO) : id(c_RVO.id) {printf ("%d: I am in move constructor\n", id);} ~RVO(){printf ("%d: I am in destructor\n", id);} }; RVO run(int i) { RVO a(i); //expecting NRVO std::atomic_thread_fence(std::memory_order_seq_cst); // simulating some synchronization here return a; } RVO f() { run(0); return run(1); } void task() { std::aligned_storage<sizeof(RVO), alignof(RVO)>::type space[1]; rvo_id = (RVO*)(space); new(space) RVO(f()); std::atomic_thread_fence(std::memory_order_seq_cst); } int main() { task(); return 0; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.33 sec, absolute running time: 0.04 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 0.37 sec
edit mode
|
history
0: I am in constructor. 0: I am in destructor 1: I am in constructor. WORKS!!!