fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <type_traits>
  4.  
  5. template <class T>
  6. T get()
  7. {
  8. static_assert(std::is_reference<T>::value, "");
  9. const static std::string s = "abc";
  10. return T(s);
  11. }
  12.  
  13. int main()
  14. {
  15. std::string& s = get<std::string&>();
  16. s = "blah"; // obviously undefined behavior!!
  17. }
  18.  
Success #stdin #stdout 0s 3424KB
stdin
Standard input is empty
stdout
Standard output is empty