[PATCH] D12895: Let cxa_demangle.cpp compile with gcc/libstdc++ 4.8 and clang-cl/MSVC2013's STL.
Nico Weber via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 15 18:48:06 PDT 2015
thakis created this revision.
thakis added a reviewer: mclow.lists.
thakis added a subscriber: cfe-commits.
I wanted a demangler that can demangle both Itanium-style and Microsoft-style mangled symbols, and that runs on all of Windows, Linux, and Mac OS X. I used libcxxabi's cxa_demangle for the Itanium demangling, but that required to get it to build with gcc on Linux and with clang-cl/MSVC on Windows. It required only small changes, and imho they look reasonable enough to send them upstream.
libstdc++ needs a few typedefs in malloc_alloc. MSVC's STL needs rebind(), construct(), destroy().
MSVC2013 also has no snprintf, but it allegedly exists in 2015. (I haven't tried building with 2015, though.)
http://reviews.llvm.org/D12895
Files:
src/cxa_demangle.cpp
Index: src/cxa_demangle.cpp
===================================================================
--- src/cxa_demangle.cpp
+++ src/cxa_demangle.cpp
@@ -18,6 +18,13 @@
#include <cstring>
#include <cctype>
+#ifdef _MSC_VER
+// snprintf is implemented in VS 2015
+#if _MSC_VER < 1900
+#define snprintf _snprintf_s
+#endif
+#endif
+
namespace __cxxabiv1
{
@@ -4818,6 +4825,12 @@
{
public:
typedef T value_type;
+ typedef T& reference;
+ typedef const T& const_reference;
+ typedef T* pointer;
+ typedef const T* const_pointer;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
malloc_alloc() = default;
template <class U> malloc_alloc(const malloc_alloc<U>&) noexcept {}
@@ -4830,6 +4843,17 @@
{
std::free(p);
}
+
+ template <class U> struct rebind { using other = malloc_alloc<U>; };
+ template <class U, class... Args>
+ void construct(U* p, Args&&... args)
+ {
+ ::new ((void*)p) U(std::forward<Args>(args)...);
+ }
+ void destroy(T* p)
+ {
+ p->~T();
+ }
};
template <class T, class U>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12895.34863.patch
Type: text/x-patch
Size: 1115 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150916/8196713a/attachment-0001.bin>
More information about the cfe-commits
mailing list