On Tue Jun 23, 2026 at 12:50 AM WEST, David Malcolm wrote:

> Minor nit: the ChangeLog entries should have references to 
>   PR analyzer/119697
> within them.
>

>> diff --git a/gcc/testsuite/g++.dg/analyzer/exception-subclass-3.C 
>> b/gcc/testsuite/g++.dg/analyzer/exception-subclass-3.C
>> new file mode 100644
>> index 00000000000..ec61789bacf
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/analyzer/exception-subclass-3.C
>> @@ -0,0 +1,123 @@
>> +#include "../../gcc.dg/analyzer/analyzer-decls.h"
>> +
>> +struct Base {};
>> +struct Derived : Base {};
>> +struct Unrelated {};
>> +
>> +struct Child : Base {};
>> +struct Grandchild : Child {};
>> +
>> +struct SiblingA : Base {};
>> +struct SiblingB : Base {};
>> +
>> +struct B1 {};
>> +struct B2 {};
>> +struct MultiDerived : B1, B2 {};
>> +
>> +struct Amb {};
>> +struct Mid1 : Amb {};
>> +struct Mid2 : Amb {};
>> +struct AmbDerived : Mid1, Mid2 {};
>> +
>> +struct PrivDerived : private Base {};
>> +
>> +void test_unrelated ()
>> +{
>> +  try {
>> +    throw Derived ();
>> +  }
>> +  catch (Unrelated &) {
>> +    __analyzer_dump_path (); // { dg-bogus "path" }
>> +  }
>> +}
>> +
>> +void test_object_vs_pointer ()
>> +{
>> +  try {
>> +    throw Derived ();
>> +  }
>> +  catch (Base *) {
>> +    __analyzer_dump_path (); // { dg-bogus "path" }
>> +  }
>> +}
>> +
>> +void test_wrong_direction ()
>> +{
>> +  try {
>> +    throw Base ();
>> +  }
>> +  catch (Derived &) {
>> +    __analyzer_dump_path (); // { dg-bogus "path" }
>> +  }
>> +}
>> +
>> +void test_pointer_base ()
>> +{
>> +  static Derived d;
>> +  try {
>> +    throw &d;
>> +  }
>> +  catch (Base *) {
>> +    __analyzer_dump_path (); // { dg-message "path" }
>> +  }
>> +}
>> +
>> +void test_grandchild ()
>> +{
>> +  try {
>> +    throw Grandchild ();
>> +  }
>> +  catch (Base &) {
>> +    __analyzer_dump_path (); // { dg-message "path" }
>> +  }
>> +}
>> +
>> +void test_sibling ()
>> +{
>> +  try {
>> +    throw SiblingA ();
>> +  }
>> +  catch (SiblingB &) {
>> +    __analyzer_dump_path (); // { dg-bogus "path" }
>> +  }
>> +}
>> +
>> +void test_multiple_inheritance ()
>> +{
>> +  try {
>> +    throw MultiDerived ();
>> +  }
>> +  catch (B1 &) {
>> +    __analyzer_dump_path (); // { dg-message "path" }
>> +  }
>> +}
>
> Can you also add a test of catching MultiDerived against B2 & please?  
> I don't think we currently have test coverage of the analyzer
> reading/writing fields of a parent class with multiple-inheritance for
> parents that aren't the first, and IIRC that involves some extra logic
> for locating where the parent is stored within the child.  Could you
> have a go at adding a test for this please (probably in a fresh
> testcase though, as it's only tangentially  related to exceptions).
>

Ok, I'll submit a v2 with these changes.

Thanks,
Egas

Reply via email to