Advertisement
Som1Lse

C++ Exceptions Codegen

Oct 24th, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. //compile with g++ test.cpp -S -o - -masm=intel
  2. //then remove the `noexcept` keyword in `int f() noexcept;` and compile again
  3. //compare the two results
  4.  
  5. #include <cstdio>
  6.  
  7. int f() noexcept;
  8.  
  9. struct s1 {
  10.     ~s1();
  11. };
  12.  
  13. struct s2 {
  14.     ~s2();
  15. };
  16.  
  17. struct s3 {
  18.     ~s3();
  19. };
  20.  
  21. int g(){
  22.     s2 s2;
  23.     return f()*f();
  24. }
  25.  
  26. int test(){
  27.     try {
  28.         s1 s1;
  29.        
  30.         auto a = g();
  31.        
  32.         s3 s3;
  33.        
  34.         return a*g();
  35.     }catch(int &e){
  36.         std::printf("e: %d\n",e);
  37.        
  38.         throw;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement