]> git.saurik.com Git - wxWidgets.git/commitdiff
A better fix for wxHash{Map,Set} with g++ 4.7.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 6 Aug 2012 11:06:45 +0000 (11:06 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 6 Aug 2012 11:06:45 +0000 (11:06 +0000)
This reverts r70556, i.e. removes the scope operators added by it to all
WX_DECLARE_HASH_{MAP,SET} macros, and implements a workaround for the problem
due to the use of empty base class optimization in g++ 4.7 standard library
implementations inside the macros themselves by prepending the hasher and
comparator classes with explicit "struct".

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72297 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/hashset.h
include/wx/html/htmlpars.h
interface/wx/hashmap.h
interface/wx/hashset.h
src/common/translation.cpp
src/generic/grid.cpp
src/xrc/xmlres.cpp
utils/wxrc/wxrc.cpp

index 2c53338ad001ed62d053b2e23a6e5fc520a74c4b..c653e9444c20df11f560f689c5a9d432d24410f1 100644 (file)
@@ -530,6 +530,7 @@ Major new features in this release
 All:
 
 - Add wxDir::Close() method (Silverstorm82).
 All:
 
 - Add wxDir::Close() method (Silverstorm82).
+- Fix compilation of wxHash{Map,Set} with g++ 4.7 (Nathan Ridge).
 
 All (GUI):
 
 
 All (GUI):
 
index 1f3368c5bf7f79239946c5e5adc6b41cc3b03e73..ae133d0618bc73aa8bc25bac678ba6891ac32283 100644 (file)
@@ -46,7 +46,7 @@
 
 // we need to define the class declared by _WX_DECLARE_HASH_SET as a class and
 // not a typedef to allow forward declaring it
 
 // we need to define the class declared by _WX_DECLARE_HASH_SET as a class and
 // not a typedef to allow forward declaring it
-#define _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, PTROP, CLASSNAME, CLASSEXP )  \
+#define _WX_DECLARE_HASH_SET_IMPL( KEY_T, HASH_T, KEY_EQ_T, PTROP, CLASSNAME, CLASSEXP )  \
 CLASSEXP CLASSNAME                                                            \
     : public WX_HASH_SET_BASE_TEMPLATE< KEY_T, HASH_T, KEY_EQ_T >             \
 {                                                                             \
 CLASSEXP CLASSNAME                                                            \
     : public WX_HASH_SET_BASE_TEMPLATE< KEY_T, HASH_T, KEY_EQ_T >             \
 {                                                                             \
@@ -69,6 +69,31 @@ public:                                                                       \
     {}                                                                        \
 }
 
     {}                                                                        \
 }
 
+// In some standard library implementations (in particular, the libstdc++ that
+// ships with g++ 4.7), std::unordered_set inherits privately from its hasher
+// and comparator template arguments for purposes of empty base optimization.
+// As a result, in the declaration of a class deriving from std::unordered_set
+// the names of the hasher and comparator classes are interpreted as naming
+// the base class which is inaccessible.
+// The workaround is to prefix the class names with 'struct'; however, don't
+// do this on MSVC because it causes a warning there if the class was
+// declared as a 'class' rather than a 'struct' (and MSVC's std::unordered_set
+// implementation does not suffer from the access problem).
+#ifdef _MSC_VER
+#define WX_MAYBE_PREFIX_WITH_STRUCT(STRUCTNAME) STRUCTNAME
+#else
+#define WX_MAYBE_PREFIX_WITH_STRUCT(STRUCTNAME) struct STRUCTNAME
+#endif
+
+#define _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, PTROP, CLASSNAME, CLASSEXP )   \
+    _WX_DECLARE_HASH_SET_IMPL(                                                \
+        KEY_T,                                                                \
+        WX_MAYBE_PREFIX_WITH_STRUCT(HASH_T),                                  \
+        WX_MAYBE_PREFIX_WITH_STRUCT(KEY_EQ_T),                                \
+        PTROP,                                                                \
+        CLASSNAME,                                                            \
+        CLASSEXP)
+
 #else // no appropriate STL class, use our own implementation
 
 // this is a complex way of defining an easily inlineable identity function...
 #else // no appropriate STL class, use our own implementation
 
 // this is a complex way of defining an easily inlineable identity function...
index cecb016c3f59e812e1aaf0beb3ccb62a160085c6..045060a4ea3a04b47060785e2323a8f49640ed1c 100644 (file)
@@ -29,7 +29,7 @@ class wxHtmlTextPieces;
 class wxHtmlParserState;
 
 WX_DECLARE_HASH_SET_WITH_DECL_PTR(wxHtmlTagHandler*,
 class wxHtmlParserState;
 
 WX_DECLARE_HASH_SET_WITH_DECL_PTR(wxHtmlTagHandler*,
-                                  ::wxPointerHash, ::wxPointerEqual,
+                                  wxPointerHash, wxPointerEqual,
                                   wxHtmlTagHandlersSet,
                                   class WXDLLIMPEXP_HTML);
 WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxHtmlTagHandler*,
                                   wxHtmlTagHandlersSet,
                                   class WXDLLIMPEXP_HTML);
 WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxHtmlTagHandler*,
index b7554e815b87e7f3b805cbbe0658c2c97783b17b..b816f836fcaafdea10a9ecbe2463524fcbcf32c3 100644 (file)
@@ -83,8 +83,8 @@
     @code
     WX_DECLARE_HASH_MAP( int,
                          wxString,
     @code
     WX_DECLARE_HASH_MAP( int,
                          wxString,
-                         ::wxIntegerHash,
-                         ::wxIntegerEqual,
+                         wxIntegerHash,
+                         wxIntegerEqual,
                          MyHash );
 
     // using an user-defined class for keys
                          MyHash );
 
     // using an user-defined class for keys
 
     WX_DECLARE_HASH_MAP( MyKey,      // type of the keys
                          SOME_TYPE,  // any type you like
 
     WX_DECLARE_HASH_MAP( MyKey,      // type of the keys
                          SOME_TYPE,  // any type you like
-                         ::MyKeyHash,  // hasher
-                         ::MyKeyEqual, // key equality predicate
+                         MyKeyHash,  // hasher
+                         MyKeyEqual, // key equality predicate
                          CLASSNAME); // name of the class
     @endcode
 
                          CLASSNAME); // name of the class
     @endcode
 
index a3406431c74495d420263e02f6d278884d037fc9..36469e47e54a831e6ceba9fda578077b10b89cd6 100644 (file)
         class MyClass { ... };
 
         // same, with MyClass* keys (only uses pointer equality!)
         class MyClass { ... };
 
         // same, with MyClass* keys (only uses pointer equality!)
-        WX_DECLARE_HASH_SET( MyClass*, ::wxPointerHash, ::wxPointerEqual, MySet1 );
+        WX_DECLARE_HASH_SET( MyClass*, wxPointerHash, wxPointerEqual, MySet1 );
         // same, with int keys
         // same, with int keys
-        WX_DECLARE_HASH_SET( int, ::wxIntegerHash, ::wxIntegerEqual, MySet2 );
+        WX_DECLARE_HASH_SET( int, wxIntegerHash, wxIntegerEqual, MySet2 );
         // declare a hash set with string keys
         // declare a hash set with string keys
-        WX_DECLARE_HASH_SET( wxString, ::wxStringHash, ::wxStringEqual, MySet3 );
+        WX_DECLARE_HASH_SET( wxString, wxStringHash, wxStringEqual, MySet3 );
 
         MySet1 h1;
         MySet2 h1;
 
         MySet1 h1;
         MySet2 h1;
@@ -70,8 +70,8 @@
 
     @code
         WX_DECLARE_HASH_SET( int,
 
     @code
         WX_DECLARE_HASH_SET( int,
-                            ::wxIntegerHash,
-                            ::wxIntegerEqual,
+                            wxIntegerHash,
+                            wxIntegerEqual,
                             MySet );
 
         // using an user-defined class for keys
                             MySet );
 
         // using an user-defined class for keys
         };
 
         WX_DECLARE_HASH_SET( MyKey,      // type of the keys
         };
 
         WX_DECLARE_HASH_SET( MyKey,      // type of the keys
-                            ::MyKeyHash,  // hasher
-                            ::MyKeyEqual, // key equality predicate
+                            MyKeyHash,  // hasher
+                            MyKeyEqual, // key equality predicate
                             CLASSNAME); // name of the class
     @endcode
 
                             CLASSNAME); // name of the class
     @endcode
 
index 379eccc45cbda2d4747bbf415993fe535157d668..c3ee0d73f2235d49f5cd27fc2ce5bab46b25aa30 100644 (file)
@@ -1440,7 +1440,7 @@ wxString wxTranslations::ChooseLanguageForDomain(const wxString& WXUNUSED(domain
 
 namespace
 {
 
 namespace
 {
-WX_DECLARE_HASH_SET(wxString, ::wxStringHash, ::wxStringEqual,
+WX_DECLARE_HASH_SET(wxString, wxStringHash, wxStringEqual,
                     wxLocaleUntranslatedStrings);
 }
 
                     wxLocaleUntranslatedStrings);
 }
 
index a4e705841f6affb5e5d5366c3222aa53d439abc1..d4d7a12b4079a29206604562225220183a312e6d 100644 (file)
@@ -72,7 +72,7 @@ const char wxGridNameStr[] = "grid";
 // Required for wxIs... functions
 #include <ctype.h>
 
 // Required for wxIs... functions
 #include <ctype.h>
 
-WX_DECLARE_HASH_SET_WITH_DECL_PTR(int, ::wxIntegerHash, ::wxIntegerEqual,
+WX_DECLARE_HASH_SET_WITH_DECL_PTR(int, wxIntegerHash, wxIntegerEqual,
                                   wxGridFixedIndicesSet, class WXDLLIMPEXP_ADV);
 
 
                                   wxGridFixedIndicesSet, class WXDLLIMPEXP_ADV);
 
 
index bd2482b47d6f79bbf0ce339da8d89471c4c749df..f39611943ba5a22b655ab71c436695283281c60f 100644 (file)
@@ -107,7 +107,7 @@ class wxXmlResourceDataRecords : public wxVector<wxXmlResourceDataRecord*>
     // this is a class so that it can be forward-declared
 };
 
     // this is a class so that it can be forward-declared
 };
 
-WX_DECLARE_HASH_SET_PTR(int, ::wxIntegerHash, ::wxIntegerEqual, wxHashSetInt);
+WX_DECLARE_HASH_SET_PTR(int, wxIntegerHash, wxIntegerEqual, wxHashSetInt);
 
 class wxIdRange // Holds data for a particular rangename
 {
 
 class wxIdRange // Holds data for a particular rangename
 {
index d6b9799e9283e0e78ae833b9949967d3448f7f51..1998c76687fdcdd2013ffa53a079e37fd8dfc07f 100644 (file)
@@ -32,7 +32,7 @@
 #include "wx/mimetype.h"
 #include "wx/vector.h"
 
 #include "wx/mimetype.h"
 #include "wx/vector.h"
 
-WX_DECLARE_HASH_SET(wxString, ::wxStringHash, ::wxStringEqual, StringSet);
+WX_DECLARE_HASH_SET(wxString, wxStringHash, wxStringEqual, StringSet);
 
 class XRCWidgetData
 {
 
 class XRCWidgetData
 {