From 02ffdd16f6664a3b81e24ced192fbeccaa4393ef Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 15 Jul 2018 14:41:58 +0200 Subject: [PATCH] Fix using WX_DECLARE_OBJARRAY() with pointer types While this doesn't make, and never made, any sense (pointers should be stored in a plain, non-object array), we still should continue to support it for compatibility. Fix the problem introduced by 97684a9267ff49d55d00151b06e89b7891e731b3 by writing "T const&" instead of "const T&" as the latter didn't have the same meaning when the macro parameter "T" expanded into "U*" as "const" applied to "U", making this type incompatible with the actual one. Also extend the unit test to check for this. --- include/wx/dynarray.h | 2 +- tests/arrays/arrays.cpp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/wx/dynarray.h b/include/wx/dynarray.h index fc58e89897..e6d5178f73 100644 --- a/include/wx/dynarray.h +++ b/include/wx/dynarray.h @@ -652,7 +652,7 @@ private: classdecl wxObjectArrayTraitsFor##name \ { \ public: \ - static T* Clone(const T& item); \ + static T* Clone(T const& item); \ static void Free(T* p); \ }; \ typedef wxBaseObjectArray \ diff --git a/tests/arrays/arrays.cpp b/tests/arrays/arrays.cpp index e991f7fc56..24c887da8e 100644 --- a/tests/arrays/arrays.cpp +++ b/tests/arrays/arrays.cpp @@ -95,6 +95,17 @@ WX_DECLARE_OBJARRAY(Bar, ArrayBars); #include "wx/arrimpl.cpp" WX_DEFINE_OBJARRAY(ArrayBars) +// ---------------------------------------------------------------------------- +// another object array test +// ---------------------------------------------------------------------------- + +// This code doesn't make any sense, as object arrays should be used with +// objects, not pointers, but it used to work, so check that it continues to +// compile. +WX_DECLARE_OBJARRAY(Bar*, ArrayBarPtrs); +#include "wx/arrimpl.cpp" +WX_DEFINE_OBJARRAY(ArrayBarPtrs) + // ---------------------------------------------------------------------------- // helpers for sorting arrays and comparing items // ---------------------------------------------------------------------------- @@ -165,6 +176,7 @@ private: CPPUNIT_TEST( wxStringArraySplitJoinTest ); CPPUNIT_TEST( wxObjArrayTest ); + CPPUNIT_TEST( wxObjArrayPtrTest ); CPPUNIT_TEST( wxArrayUShortTest ); CPPUNIT_TEST( wxArrayIntTest ); CPPUNIT_TEST( wxArrayCharTest ); @@ -181,6 +193,7 @@ private: void wxStringArrayJoinTest(); void wxStringArraySplitJoinTest(); void wxObjArrayTest(); + void wxObjArrayPtrTest(); void wxArrayUShortTest(); void wxArrayIntTest(); void wxArrayCharTest(); @@ -567,6 +580,13 @@ void ArraysTestCase::wxObjArrayTest() CPPUNIT_ASSERT_EQUAL( 0, Bar::GetNumber() ); } +void ArraysTestCase::wxObjArrayPtrTest() +{ + // Just check that instantiating this class compiles. + ArrayBarPtrs barptrs; + CPPUNIT_ASSERT_EQUAL( 0, barptrs.size() ); +} + #define TestArrayOf(name) \ \ void ArraysTestCase::wxArray ## name ## Test() \