Преглед на файлове

Merge pull request #1299 from tatraian/master

Fix compiling clang/libc++ builds. (Issue: #1266)
Feng Xiao преди 9 години
родител
ревизия
48ebb29a8e
променени са 1 файла, в които са добавени 5 реда и са изтрити 1 реда
  1. 5 1
      src/google/protobuf/map.h

+ 5 - 1
src/google/protobuf/map.h

@@ -548,7 +548,11 @@ class Map {
     !defined(GOOGLE_PROTOBUF_OS_NACL) && !defined(GOOGLE_PROTOBUF_OS_ANDROID)
     template<class NodeType, class... Args>
     void construct(NodeType* p, Args&&... args) {
-      new (static_cast<void*>(p)) NodeType(std::forward<Args>(args)...);
+      // Clang 3.6 doesn't compile static casting to void* directly. (Issue #1266)
+      // According C++ standard 5.2.9/1: "The static_cast operator shall not cast
+      // away constness". So first the maybe const pointer is casted to const void* and
+      // after the const void* is const casted.
+      new (const_cast<void*>(static_cast<const void*>(p))) NodeType(std::forward<Args>(args)...);
     }
 
     template<class NodeType>