Using the same version of GCC/Clang, is there a way to ensure typeid gives different results for the same type in two different DSOs, such that dynamic_cast and/or catching an exception across a DSO boundary will fail?
Frustratingly, I have seen the case where an exception wasn't caught when thrown across a DSO boundary, and I had to add __attribute__((visibility("default"))) to the exception class to make it work. But I can't remember where or in what circumstance. And now I can't reproduce it in a toy example!
I've been trying to come up with an example with two linked libraries (or library and executable), both compiled with -fvisibility=hidden, and both #includeing the same header defining some inline polymorphic (virtual) classes.
But for the life of me, tooling around in Compiler Explorer, I can't seem to break it. The type_info seems to evaluate the same (e.g. has the same .hash_code()) in both DSOs, and accordingly dynamic_casts and catching exceptions work across DSOs.
Can anyone give some hint as to what circumstances this will actually fail?