r359048 - C++ DR2387: a variable template declared wtih (or instantiated with) a

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 24 14:25:53 PDT 2019


On Wed, 24 Apr 2019 at 13:28, Richard Smith <richard at metafoo.co.uk> wrote:
>
> Thanks for the revert.
>
> Looks like this is probably an unfortunate interaction with the internal_linkage attribute.

I think this is a libc++ bug. When
_LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT is enabled, we have:

#define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
#define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI

template<class _Tp> class valarray {
public:
  // ...
  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
  explicit valarray(size_t __n); // defined later in this header
  // ...
};

_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::valarray(size_t))

So: we declare valarray<T>::valarray(size_t) as having internal
linkage, then add an explicit instantiation declaration for it. This
means any use of it can result in a link error (if it happens to not
be inlined): we disallow linking against a version from a different
TU, but also disallow implicit instantiation in the current TU. This
happens to work prior to my patch only by chance: in a conflict
between available_externally and internal linkage, clang happens to
pick internal.

> On Wed, 24 Apr 2019, 01:48 Ilya Biryukov via cfe-commits, <cfe-commits at lists.llvm.org> wrote:
>>
>> Reverted in r359076.
>>
>> On Wed, Apr 24, 2019 at 10:28 AM Ilya Biryukov <ibiryukov at google.com> wrote:
>>>
>>> Hi Richard,
>>>
>>> This seems to break libc++, found while doing an integrate. The errors are:
>>>
>>> In file included from valarray:4:
>>> .../include/c++/v1/valarray:1062:60: error: explicit instantiation declaration of 'valarray<_Tp>' with internal linkage
>>> _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::valarray(size_t))
>>>                                                            ^
>>> .../include/c++/v1/valarray:1063:60: error: explicit instantiation declaration of '~valarray<_Tp>' with internal linkage
>>> _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::~valarray())
>>>                                                            ^
>>>
>>> I will likely revert the change to unbreak the integrate.
>>>
>>
>>
>> --
>> Regards,
>> Ilya Biryukov
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list