https://github.com/unterumarmung commented:

Please also add the following test cases:

1. **Function try blocks**
   ```cpp
   struct X {
     X() try {
       f();
     } catch (const E &e) {
       throw e;
     }
   };
   ```

2. **Nested try blocks**
   ```cpp
   try {
     try {
       f();
     } catch (const E &e) {
       throw e;
     }
   } catch (...) {}
   ```

3. **Consecutive try blocks**  
   Multiple `try`/`catch` blocks one after another, to make sure the warning is 
emitted independently for each block and state does not leak between them.

4. **Comments in various positions**
   - before `throw`
   - between `throw` and the exception object
   - between the exception object and `;`

5. **Throws inside templates**  
   Cases where `throw e;` appears in templated code, to verify the warning 
still works correctly in dependent or instantiated contexts.

6. **No warning inside a local class**
   ```cpp
   catch (const E &e) {
     struct X {
       static void h(const E &e) { throw e; } // no warning
     };
   }
   ```

7. **No warning inside a lambda**
   ```cpp
   catch (const E &e) {
     [&] { throw e; }(); // should this warn? probably not
   }
   ```

8. **Bare rethrow**
   ```cpp
   catch (...) {
     throw; // no warning
   }
   ```

9. **Parenthesized exception object should still warn**
   ```cpp
   catch (const MyException &e) { throw (e); }     // should warn
   catch (const MyException &e) { throw (((e))); } // should warn
   ```

10. **Volatile caught exception**
   ```cpp
   catch (volatile MyException &e) { throw e; } // probably should warn, if 
allowed
   ```

11. **Warning inside a conditional branch**
   ```cpp
   catch (const std::exception &e) {
     if (cond) {
       throw e; // warning; fix to throw;
     }
   }
   ```

12. **No warning for shadowed variable**
   ```cpp
   catch (const std::exception &e) {
     {
       MyException e;
       throw e; // no warning: inner variable shadows the caught exception
     }
   }
   ```

13. **Throwing a wrapper exception**
   ```cpp
   catch (const std::exception &e) {
     throw WrapperException(e);
   }
   ```
   This should not warn, because it throws a new exception object rather than 
rethrowing the caught one by name.


https://github.com/llvm/llvm-project/pull/190580
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to