Skip to content

Commit 1344745

Browse files
committedJan 30, 2019
[libc++] Don't define operator new/delete when using vcruntime
Fixes build errors on Windows without libc++abi of the form: new(173,36): error: redeclaration of 'operator delete' cannot add 'dllexport' attribute _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT; vcruntime_new.h(87,16): note: previous declaration is here void __CRTDECL operator delete( new(205,70): error: redefinition of 'operator new' _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;} vcruntime_new.h(184,28): note: previous definition is here inline void* __CRTDECL operator new(size_t _Size, _Writable_bytes_(_Size) void* _Where) noexcept new(206,70): error: redefinition of 'operator new[]' _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;} vcruntime_new.h(199,28): note: previous definition is here inline void* __CRTDECL operator new[](size_t _Size, new(207,40): error: redefinition of 'operator delete' inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {} vcruntime_new.h(190,27): note: previous definition is here inline void __CRTDECL operator delete(void*, void*) noexcept new(208,40): error: redefinition of 'operator delete[]' inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {} vcruntime_new.h(206,27): note: previous definition is here inline void __CRTDECL operator delete[](void*, void*) noexcept Differential Revision: https://reviews.llvm.org/D57362 llvm-svn: 352647
1 parent 095ed05 commit 1344745

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
 

‎libcxx/include/__config

+8-7
Original file line numberDiff line numberDiff line change
@@ -985,17 +985,18 @@ template <unsigned> struct __static_assert_check {};
985985
#define _DECLARE_C99_LDBL_MATH 1
986986
#endif
987987

988+
#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
989+
# define _LIBCPP_DEFER_NEW_TO_VCRUNTIME
990+
#endif
991+
988992
// If we are getting operator new from the MSVC CRT, then allocation overloads
989993
// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
990994
#if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
991995
# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
992-
#elif defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
993-
# define _LIBCPP_DEFER_NEW_TO_VCRUNTIME
994-
# if !defined(__cpp_aligned_new)
995-
// We're defering to Microsoft's STL to provide aligned new et al. We don't
996-
// have it unless the language feature test macro is defined.
997-
# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
998-
# endif
996+
#elif defined(_LIBCPP_DEFER_NEW_TO_VCRUNTIME) && !defined(__cpp_aligned_new)
997+
// We're defering to Microsoft's STL to provide aligned new et al. We don't
998+
// have it unless the language feature test macro is defined.
999+
# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
9991000
#endif
10001001

10011002
#if defined(__APPLE__)

0 commit comments

Comments
 (0)
Please sign in to comment.