Fix wxCALL_FOR_EACH() to work with more than 2 arguments with MSVC.
Due to a bug in MSVC handling of __VA_ARGS__ (see https://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement) wxCALL_FOR_EACH() didn't work correctly as long as more than two arguments were used with it. Work around the bug by protecting __VA_ARGS__ from being incorrectly passed as a single token to the macro being called on every step: this was already done for wxCALL_FOR_EACH itself with wxCALL_FOR_EACH_, but we need to do it for all the helper macros too. Also add a test checking that this does, actually, work. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77689 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -35,11 +35,15 @@ public:
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( MiscTestCase );
|
||||
CPPUNIT_TEST( Assert );
|
||||
#ifdef HAVE_VARIADIC_MACROS
|
||||
CPPUNIT_TEST( CallForEach );
|
||||
#endif // HAVE_VARIADIC_MACROS
|
||||
CPPUNIT_TEST( Delete );
|
||||
CPPUNIT_TEST( StaticCast );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void Assert();
|
||||
void CallForEach();
|
||||
void Delete();
|
||||
void StaticCast();
|
||||
|
||||
@@ -75,6 +79,20 @@ void MiscTestCase::Assert()
|
||||
wxSetAssertHandler(oldHandler);
|
||||
}
|
||||
|
||||
#ifdef HAVE_VARIADIC_MACROS
|
||||
void MiscTestCase::CallForEach()
|
||||
{
|
||||
#define MY_MACRO(pos, str) s += str;
|
||||
|
||||
wxString s;
|
||||
wxCALL_FOR_EACH(MY_MACRO, "foo", "bar", "baz");
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( "foobarbaz", s );
|
||||
|
||||
#undef MY_MACRO
|
||||
}
|
||||
#endif // HAVE_VARIADIC_MACROS
|
||||
|
||||
void MiscTestCase::Delete()
|
||||
{
|
||||
// Allocate some arbitrary memory to get a valid pointer:
|
||||
|
Reference in New Issue
Block a user