Fixed ambiguity in casting size_t to one of unsigned type (found in AIX 32bit target)
authorkhizmax <libcds.dev@gmail.com>
Tue, 30 May 2017 20:34:39 +0000 (23:34 +0300)
committerkhizmax <libcds.dev@gmail.com>
Tue, 30 May 2017 20:34:39 +0000 (23:34 +0300)
cds/details/size_t_cast.h [new file with mode: 0644]
cds/intrusive/details/split_list_base.h
projects/Win/vc14/cds.vcxproj
projects/Win/vc14/cds.vcxproj.filters
projects/Win/vc141/cds.vcxproj
projects/Win/vc141/cds.vcxproj.filters

diff --git a/cds/details/size_t_cast.h b/cds/details/size_t_cast.h
new file mode 100644 (file)
index 0000000..f79dbd9
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+This file is a part of libcds - Concurrent Data Structures library
+
+(C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
+
+Source code repo: http://github.com/khizmax/libcds/
+Download: http://sourceforge.net/projects/libcds/files/
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef CDSLIB_DETAILS_SIZE_T_CAST_H
+#define CDSLIB_DETAILS_SIZE_T_CAST_H
+
+#include <cds/details/defs.h>
+
+//@cond
+namespace cds { namespace details {
+
+    template <size_t Size>
+    struct size_t_unsigned;
+
+    template <>
+    struct size_t_unsigned<4>
+    {
+        typedef uint32_t type;
+    };
+
+    template <>
+    struct size_t_unsigned<8>
+    {
+        typedef uint64_t type;
+    };
+
+    static inline size_t_unsigned<sizeof( size_t )>::type size_t_cast( size_t n )
+    {
+        return static_cast< size_t_unsigned<sizeof( size_t )>::type>( n );
+    }
+
+}} // namespace cds::details
+//@endcond
+
+#endif // #ifndef CDSLIB_DETAILS_SIZE_T_CAST_H
+
index e4ef11adf928aa909927a14941bba0ad41a61618..ce7c299ef57b9cbba1777676a9ee03cc1ee9f8fe 100644 (file)
@@ -39,6 +39,7 @@
 #include <cds/algo/bitop.h>
 #include <cds/opt/hash.h>
 #include <cds/intrusive/free_list_selector.h>
+#include <cds/details/size_t_cast.h>
 
 namespace cds { namespace intrusive {
 
@@ -1302,13 +1303,13 @@ namespace cds { namespace intrusive {
         template <typename BitReversalAlgo>
         static inline size_t regular_hash( size_t nHash )
         {
-            return BitReversalAlgo()( nHash ) | size_t(1);
+            return static_cast<size_t>( BitReversalAlgo()( cds::details::size_t_cast( nHash ))) | size_t(1);
         }
 
         template <typename BitReversalAlgo>
         static inline size_t dummy_hash( size_t nHash )
         {
-            return BitReversalAlgo()( nHash ) & ~size_t(1);
+            return static_cast<size_t>( BitReversalAlgo()( cds::details::size_t_cast( nHash ))) & ~size_t(1);
         }
         //@endcond
 
index 91071fe4bc4f7998cbe887df88e590787c069c5c..12aeea18a97f0048f0e411509370a179cae3ec90 100644 (file)
     <ClInclude Include="..\..\..\cds\details\bit_reverse_counter.h" />\r
     <ClInclude Include="..\..\..\cds\details\bounded_container.h" />\r
     <ClInclude Include="..\..\..\cds\details\lib.h" />\r
+    <ClInclude Include="..\..\..\cds\details\size_t_cast.h" />\r
     <ClInclude Include="..\..\..\cds\details\static_functor.h" />\r
     <ClInclude Include="..\..\..\cds\details\throw_exception.h" />\r
     <ClInclude Include="..\..\..\cds\gc\details\hp_common.h" />\r
index f362b391fd34f8c62ea86c48818abd6e51519da5..5987d4bf52617a787af84aacd3e782435689e592 100644 (file)
     <ClInclude Include="..\..\..\cds\container\weak_ringbuffer.h">\r
       <Filter>Header Files\cds\container</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="..\..\..\cds\details\size_t_cast.h">\r
+      <Filter>Header Files\cds\details</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
 </Project>
\ No newline at end of file
index a74adfc68bdc9eeb091a83ae15bde69a4a72b4ca..ace327b5e4ce8842b4c40b7995098ccf91bc88c4 100644 (file)
     <ClInclude Include="..\..\..\cds\details\bit_reverse_counter.h" />
     <ClInclude Include="..\..\..\cds\details\bounded_container.h" />
     <ClInclude Include="..\..\..\cds\details\lib.h" />
+    <ClInclude Include="..\..\..\cds\details\size_t_cast.h" />
     <ClInclude Include="..\..\..\cds\details\static_functor.h" />
     <ClInclude Include="..\..\..\cds\details\throw_exception.h" />
     <ClInclude Include="..\..\..\cds\gc\details\hp_common.h" />
index 137444c8c7c6978afc1d86947c0b101e7ba47d1a..04f33e0030c56c165323675869b10866132274f8 100644 (file)
     <ClInclude Include="..\..\..\cds\container\weak_ringbuffer.h">
       <Filter>Header Files\cds\container</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\..\cds\details\size_t_cast.h">
+      <Filter>Header Files\cds\details</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>
\ No newline at end of file