fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <utility>
  4. #include <type_traits>
  5.  
  6. using namespace std;
  7.  
  8. template<typename T>
  9. void push_back(T&& newt){
  10. typedef typename std::remove_reference<T>::type Type;
  11.  
  12. Type* ptr=(Type*)operator new(sizeof(Type)); //memory leak but w/e
  13. new (ptr) Type(std::forward<T>(newt));
  14. }
  15.  
  16. int main(){
  17. string d="hi";
  18. push_back(d); //the problematic line
  19. push_back(std::move(d));
  20.  
  21. return 1;
  22. }
  23.  
Runtime error #stdin #stdout 0s 2980KB
stdin
Standard input is empty
stdout
Standard output is empty