fork download
  1. #include <iostream>
  2.  
  3. #include <string>
  4.  
  5. namespace safer {
  6. template<class CharT,
  7. class Traits = std::char_traits<CharT>,
  8. class Allocator = std::allocator<CharT>,
  9. class Base = std::basic_string<CharT, Traits, Allocator>
  10. >
  11. struct basic_string:
  12. Base
  13. {
  14. using Base::Base;
  15. basic_string( CharT const* ptr ):
  16. Base( ptr?Base(ptr):Base() )
  17. {}
  18. template<class T,
  19. typename std::enable_if<std::is_same<T, int>::value, bool>::type = true
  20. >
  21. basic_string(T&&)=delete;
  22. };
  23. using string = basic_string<char>;
  24. using wstring = basic_string<wchar_t>;
  25. }
  26.  
  27. void crash(const safer::string& s) {}
  28. int main()
  29. {
  30. try
  31. {
  32. crash(0);
  33. }
  34. catch (const std::exception& ex)
  35. {
  36. // never gets here!
  37. std::cout << "got" << ex.what() << std::endl;
  38. }
  39. }
  40.  
  41. int main() {
  42. // your code goes here
  43. return 0;
  44. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:32:16: error: use of deleted function ‘safer::basic_string<CharT, Traits, Allocator, Base>::basic_string(T&&) [with T = int; typename std::enable_if<std::is_same<T, int>::value, bool>::type <anonymous> = 1u; CharT = char; Traits = std::char_traits<char>; Allocator = std::allocator<char>; Base = std::__cxx11::basic_string<char>]’
         crash(0);
                ^
prog.cpp:21:4: note: declared here
    basic_string(T&&)=delete;
    ^~~~~~~~~~~~
prog.cpp: In function ‘int main()’:
prog.cpp:41:5: error: redefinition of ‘int main()’
 int main() {
     ^~~~
prog.cpp:28:5: note: ‘int main()’ previously defined here
 int main()
     ^~~~
stdout
Standard output is empty