Don't define interfaces inside anonymous namespace in wxMSW

Some interfaces, notably IAutoCompleteDropDown, but also several other ones in
taskbarbutton.cpp, were defined inside anonymous namespace to avoid clashing
with the interfaces possibly (but not necessarily) declared in the standard
headers.

However gcc 4.9 is smart enough to realize that no classes deriving from a
class in an anonymous namespace can exist and so it devirtualizes the calls to
virtual methods of the objects of this type when compiling with optimizations
enabled. And it does it even if it means replacing the call to a virtual
method with just a call to __cxa_pure_virtual(), i.e. crashing during
run-time.

Prevent it from doing this by moving class declarations outside of the
anonymous namespace and fix the crash when using wxTextEntry::AutoComplete()
in the code compiled with g++ 4.9.
This commit is contained in:
Vadim Zeitlin 2016-02-11 23:39:44 +01:00
parent 1908c41f36
commit 4475fe36a5
2 changed files with 56 additions and 51 deletions

View File

@ -148,6 +148,56 @@ DEFINE_PROPERTYKEY(PKEY_AppUserModel_IsDestListSeparator,
DEFINE_PROPERTYKEY(PKEY_Link_Arguments,
0x436f2667, 0x14e2, 0x4feb, 0xb3, 0x0a, 0x14, 0x6c, 0x53, 0xb5, 0xb6, 0x74, 100);
#ifdef wxUSE_UNICODE
#define IShellLink wxIShellLinkW
DEFINE_GUID(wxIID_IShellLink,
0x000214F9, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
#else
#define IShellLink wxIShellLinkA
DEFINE_GUID(wxIID_IShellLink,
0x000214EE, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
#endif // wxUSE_UNICODE
typedef enum _SIGDN
{
SIGDN_NORMALDISPLAY = 0,
SIGDN_PARENTRELATIVEPARSING = (int)0x80018001,
SIGDN_DESKTOPABSOLUTEPARSING = (int)0x80028000,
SIGDN_PARENTRELATIVEEDITING = (int)0x80031001,
SIGDN_DESKTOPABSOLUTEEDITING = (int)0x8004c000,
SIGDN_FILESYSPATH = (int)0x80058000,
SIGDN_URL = (int)0x80068000,
SIGDN_PARENTRELATIVEFORADDRESSBAR = (int)0x8007c001,
SIGDN_PARENTRELATIVE = (int)0x80080001
} SIGDN;
enum _SICHINTF
{
SICHINT_DISPLAY = 0,
SICHINT_ALLFIELDS = (int)0x80000000,
SICHINT_CANONICAL = 0x10000000,
SICHINT_TEST_FILESYSPATH_IF_NOT_EQUAL = 0x20000000
};
typedef DWORD SICHINTF;
typedef ULONG SFGAOF;
typedef enum KNOWNDESTCATEGORY
{
KDC_FREQUENT = 1,
KDC_RECENT = ( KDC_FREQUENT + 1 )
} KNOWNDESTCATEGORY;
typedef enum APPDOCLISTTYPE
{
ADLT_RECENT = 0,
ADLT_FREQUENT = ( ADLT_RECENT + 1 )
} APPDOCLISTTYPE;
} // anonymous namespace
class wxITaskbarList : public IUnknown
{
public:
@ -210,42 +260,6 @@ public:
virtual HRESULT wxSTDCALL SetPath(LPCWSTR) = 0;
};
#ifdef wxUSE_UNICODE
#define IShellLink wxIShellLinkW
DEFINE_GUID(wxIID_IShellLink,
0x000214F9, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
#else
#define IShellLink wxIShellLinkA
DEFINE_GUID(wxIID_IShellLink,
0x000214EE, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
#endif // wxUSE_UNICODE
typedef enum _SIGDN
{
SIGDN_NORMALDISPLAY = 0,
SIGDN_PARENTRELATIVEPARSING = (int)0x80018001,
SIGDN_DESKTOPABSOLUTEPARSING = (int)0x80028000,
SIGDN_PARENTRELATIVEEDITING = (int)0x80031001,
SIGDN_DESKTOPABSOLUTEEDITING = (int)0x8004c000,
SIGDN_FILESYSPATH = (int)0x80058000,
SIGDN_URL = (int)0x80068000,
SIGDN_PARENTRELATIVEFORADDRESSBAR = (int)0x8007c001,
SIGDN_PARENTRELATIVE = (int)0x80080001
} SIGDN;
enum _SICHINTF
{
SICHINT_DISPLAY = 0,
SICHINT_ALLFIELDS = (int)0x80000000,
SICHINT_CANONICAL = 0x10000000,
SICHINT_TEST_FILESYSPATH_IF_NOT_EQUAL = 0x20000000
};
typedef DWORD SICHINTF;
typedef ULONG SFGAOF;
class IShellItem : public IUnknown
{
public:
@ -282,12 +296,6 @@ public:
virtual HRESULT wxSTDCALL Commit() = 0;
};
typedef enum KNOWNDESTCATEGORY
{
KDC_FREQUENT = 1,
KDC_RECENT = ( KDC_FREQUENT + 1 )
} KNOWNDESTCATEGORY;
class ICustomDestinationList : public IUnknown
{
public:
@ -302,12 +310,6 @@ public:
virtual HRESULT wxSTDCALL AbortList() = 0;
};
typedef enum APPDOCLISTTYPE
{
ADLT_RECENT = 0,
ADLT_FREQUENT = ( ADLT_RECENT + 1 )
} APPDOCLISTTYPE;
class IApplicationDocumentLists : public IUnknown
{
public:
@ -315,6 +317,9 @@ public:
virtual HRESULT wxSTDCALL GetList(APPDOCLISTTYPE, UINT, REFIID, void**) = 0;
};
namespace
{
inline HRESULT InitPropVariantFromBoolean(BOOL fVal, PROPVARIANT *ppropvar)
{
ppropvar->vt = VT_BOOL;

View File

@ -83,9 +83,6 @@
// above.
#include <initguid.h>
namespace
{
// Normally this interface and its IID are defined in shobjidl.h header file
// included in the platform SDK but MinGW and Cygwin don't have it so redefine
// the interface ourselves and, as long as we do it all, do it for all
@ -98,6 +95,9 @@ public:
virtual HRESULT wxSTDCALL ResetEnumerator() = 0;
};
namespace
{
DEFINE_GUID(wxIID_IAutoCompleteDropDown,
0x3cd141f4, 0x3c6a, 0x11d2, 0xbc, 0xaa, 0x00, 0xc0, 0x4f, 0xd9, 0x29, 0xdb);