[libcxx] r284016 - [libc++] Correct explanation of _LIBCPP_NEW_DELETE_VIS

Shoaib Meenai via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 12 06:48:14 PDT 2016


Author: smeenai
Date: Wed Oct 12 08:48:14 2016
New Revision: 284016

URL: http://llvm.org/viewvc/llvm-project?rev=284016&view=rev
Log:
[libc++] Correct explanation of _LIBCPP_NEW_DELETE_VIS

The behavior of this macro actually needs to apply universally on
Windows and not just when using the Microsoft CRT. Update the macro
definition and documentation accordingly.

Differential Revision: https://reviews.llvm.org/D25145

Modified:
    libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst
    libcxx/trunk/include/new

Modified: libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst?rev=284016&r1=284015&r2=284016&view=diff
==============================================================================
--- libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst (original)
+++ libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst Wed Oct 12 08:48:14 2016
@@ -112,14 +112,15 @@ Visibility Macros
   Mark a symbol as being exported by the libc++ library. This macro must be
   applied to all `operator new` and `operator delete` overloads.
 
-  **Windows Behavior**: When using the Microsoft CRT, all the `operator new` and
-  `operator delete` overloads are defined statically in `msvcrt.lib`. Marking
-  them as `dllimport` in the libc++ `<new>` header is therefore undesirable: if
-  we were to mark them as `dllimport` and then link against libc++, source files
-  which included `<new>` would end up linking against libc++'s `operator new`
-  and `operator delete`, while source files which did not include `<new>` would
-  end up linking against msvcrt's `operator new` and `operator delete`, which
-  would be a confusing and potentially error-prone inconsistency.
+  **Windows Behavior**: The `operator new` and `operator delete` overloads
+  should not be marked as `dllimport`; if they were, source files including the
+  `<new>` header (either directly or transitively) would lose the ability to use
+  local overloads of `operator new` and `operator delete`. On Windows, this
+  macro therefore expands to `__declspec(dllexport)` when building the library
+  and has an empty definition otherwise. A related caveat is that libc++ must be
+  included on the link line before `msvcrt.lib`, otherwise Microsoft's
+  definitions of `operator new` and `operator delete` inside `msvcrt.lib` will
+  end up being used instead of libc++'s.
 
 Links
 =====

Modified: libcxx/trunk/include/new
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/new?rev=284016&r1=284015&r2=284016&view=diff
==============================================================================
--- libcxx/trunk/include/new (original)
+++ libcxx/trunk/include/new Wed Oct 12 08:48:14 2016
@@ -125,7 +125,7 @@ _LIBCPP_FUNC_VIS new_handler get_new_han
 
 }  // std
 
-#if defined(_LIBCPP_MSVCRT) && !defined(_LIBCPP_BUILDING_LIBRARY)
+#if defined(_WIN32) && !defined(_LIBCPP_BUILDING_LIBRARY)
 # define _LIBCPP_NEW_DELETE_VIS
 #else
 # define _LIBCPP_NEW_DELETE_VIS _LIBCPP_FUNC_VIS




More information about the cfe-commits mailing list