[libcxx-commits] [libcxx] c793f68 - [libcxx] Don't use dllimport for a static member in a template

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 3 23:10:49 PST 2021


Author: Martin Storsjö
Date: 2021-03-04T08:55:27+02:00
New Revision: c793f68d9b62e9813f17d438be5edd23f348b4b9

URL: https://github.com/llvm/llvm-project/commit/c793f68d9b62e9813f17d438be5edd23f348b4b9
DIFF: https://github.com/llvm/llvm-project/commit/c793f68d9b62e9813f17d438be5edd23f348b4b9.diff

LOG: [libcxx] Don't use dllimport for a static member in a template

This fixes clang warnings (that are treated as errors when running
the test suite):

libcxx/include/string:4409:59: error: definition of dllimport static field [-Werror,-Wdllimport-static-field-def]
               basic_string<_CharT, _Traits, _Allocator>::npos;

The warning is normally not visible as long as the libc++ headers
are treated as system headers.

The same construct is always an error in MSVC.

(One _LIBCPP_FUNC_VIS was added in
2d8f23f571635c1fb983b40c4c2548716a5b65b6, which broke DLL builds.
59919c4d6b6370da7133bbca0d31844e21646bb1 fixed this by adding another
_LIBCPP_FUNC_VIS on the declaration for consistency, but the underlying
issue remained, that one can't use dllimport here.)

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

Added: 
    

Modified: 
    libcxx/include/__config
    libcxx/include/string

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__config b/libcxx/include/__config
index 9d199151e69b..f2874e6d3f65 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -640,6 +640,7 @@ typedef __char32_t char32_t;
 #define _LIBCPP_HIDDEN
 #define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
 #define _LIBCPP_TEMPLATE_VIS
+#define _LIBCPP_TEMPLATE_DATA_VIS
 #define _LIBCPP_ENUM_VIS
 
 #endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
@@ -689,6 +690,14 @@ typedef __char32_t char32_t;
 #  endif
 #endif
 
+#ifndef _LIBCPP_TEMPLATE_DATA_VIS
+#  if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
+#    define _LIBCPP_TEMPLATE_DATA_VIS __attribute__ ((__visibility__("default")))
+#  else
+#    define _LIBCPP_TEMPLATE_DATA_VIS
+#  endif
+#endif
+
 #ifndef _LIBCPP_EXPORTED_FROM_ABI
 #  if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
 #    define _LIBCPP_EXPORTED_FROM_ABI __attribute__((__visibility__("default")))

diff  --git a/libcxx/include/string b/libcxx/include/string
index b0521641670a..19bd22b3acf5 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -805,7 +805,7 @@ private:
     __compressed_pair<__rep, allocator_type> __r_;
 
 public:
-    _LIBCPP_FUNC_VIS
+    _LIBCPP_TEMPLATE_DATA_VIS
     static const size_type npos = -1;
 
     _LIBCPP_INLINE_VISIBILITY basic_string()
@@ -4404,7 +4404,7 @@ _LIBCPP_FUNC_VIS wstring to_wstring(double __val);
 _LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
 
 template<class _CharT, class _Traits, class _Allocator>
-_LIBCPP_FUNC_VIS
+_LIBCPP_TEMPLATE_DATA_VIS
 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
                basic_string<_CharT, _Traits, _Allocator>::npos;
 


        


More information about the libcxx-commits mailing list