Use the same wxWeakRef implementation for complete and incomplete classes.

This fixes an ODR violation which could arise if wxWeakRef<T> was seen both
when T was an incomplete (e.g. just forward-defined) class and when it was
complete. As different implementations, with different binary layouts, were
used in these two cases, this resulted in fatal run-time problems.

Fix this by always using the slightly less efficient (because storing an extra
pointer) but simpler and safe "dynamic" wxWeakRef implementation.

Also get rid of checks for the ancient compilers such as VC6 and g++ < 3.3,
they are not supported any longer.

Closes #15884.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76316 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-04-12 00:10:54 +00:00
parent 0ed46e37fa
commit 72aad0d6ea
4 changed files with 75 additions and 164 deletions

View File

@@ -83,6 +83,9 @@ wxWeakRef<ForwardDeclaredClass> g_incompleteWeakRef;
struct ForwardDeclaredClass : wxEvtHandler { };
// A incomplete class that would be defined in other compilation units
struct IncompleteClass;
void WeakRefTestCase::DeclareTest()
{
{
@@ -128,6 +131,21 @@ void WeakRefTestCase::DeclareTest()
CPPUNIT_ASSERT( !g_incompleteWeakRef );
#endif // RTTI enabled
{
// Construction of a wxWeakRef to an incomplete class should be fine
wxWeakRef<IncompleteClass> p;
// Copying should be also OK
p = p;
// Assigning a raw pointer should cause compile error
#ifdef TEST_INVALID_INCOMPLETE_WEAKREF
p = static_cast<IncompleteClass*>(0);
#endif
// Releasing should be OK
}
}
void WeakRefTestCase::AssignTest()