From e1c9dfba1a33d58537fcd3fe39e4ecb1c82541d6 Mon Sep 17 00:00:00 2001 From: Shoaib Meenai Date: Thu, 13 Apr 2017 20:13:32 +0000 Subject: [PATCH] [libc++] Add _LIBCPP_DISABLE_EXTERN_TEMPLATE config option When the libc++ extern template macros were added, the intent was for it to be possible for consumers of the headers to disable extern templates (via `-D_LIBCPP_EXTERN_TEMPLATE(...)=`). Unfortunately, support for specifying function-like macros varies on the command line varies across compilers (e.g. MSVC doesn't support it at all), and cmake doesn't allow it for the same reason. Add a non-function macro for this purpose. The intended use is for libraries which want to use the libc++ headers without taking a dependency on the libc++ library itself. I can name the macro something which reflects its intent rather than its behavior (e.g. `_LIBCPP_HEADER_ONLY`) if desired. Differential Revision: https://reviews.llvm.org/D31725 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@300246 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/UsingLibcxx.rst | 5 +++++ include/__config | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/docs/UsingLibcxx.rst b/docs/UsingLibcxx.rst index fe32f5e6b..183664655 100644 --- a/docs/UsingLibcxx.rst +++ b/docs/UsingLibcxx.rst @@ -146,6 +146,11 @@ thread safety annotations. build of libc++ which does not export any symbols, which can be useful when building statically for inclusion into another library. +**_LIBCPP_DISABLE_EXTERN_TEMPLATE**: + This macro is used to disable extern template declarations in the libc++ + headers. The intended use case is for clients who wish to use the libc++ + headers without taking a dependency on the libc++ library itself. + **_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION**: This macro is used to re-enable an extension in `std::tuple` which allowed it to be implicitly constructed from fewer initializers than contained diff --git a/include/__config b/include/__config index 117d2d61f..bca85b6e3 100644 --- a/include/__config +++ b/include/__config @@ -856,6 +856,11 @@ template struct __static_assert_check {}; # endif #endif +#ifdef _LIBCPP_DISABLE_EXTERN_TEMPLATE +#define _LIBCPP_EXTERN_TEMPLATE(...) +#define _LIBCPP_EXTERN_TEMPLATE2(...) +#endif + #ifndef _LIBCPP_EXTERN_TEMPLATE #define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__; #endif