目标C++ ARC 和 C++ 容器



我正在尝试编译我的无遗留libFoundation项目,该项目位于 https://github.com/chmeeedalf/lf-foundation,但在使用clang 3.4和libc ++时遇到了问题。 容器中的 ARC 似乎有些不满意,我看到以下错误摘录:

In file included from /home/chmeee/git-lffoundation/src/Collections/NSCoreArray.mm:34:
In file included from /home/chmeee/git-lffoundation/src/../Headers/Foundation/NSArray.h:31:
In file included from /home/chmeee/git-lffoundation/src/../Headers/Foundation/NSObject.h:40:
In file included from /home/chmeee/git-lffoundation/src/../Headers/Foundation/NSRange.h:192:
In file included from /usr/include/c++/v1/algorithm:627:
/usr/include/c++/v1/memory:913:17: error: call to 'addressof' is ambiguous
        {return _VSTD::addressof(__r);}
                ^~~~~~~~~~~~~~~~
/usr/include/c++/v1/__config:341:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
              ^
/usr/include/c++/v1/vector:1678:65: note: in instantiation of member function 'std::__1::pointer_traits<const __strong id *>::pointer_to' requested here
            const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
                                                                ^
/home/chmeee/git-lffoundation/src/Collections/NSCoreArray.mm:115:8: note: in instantiation of member function 'std::__1::vector<id, std::__1::allocator<id> >::insert' requested here
        items.insert(items.begin() + index, anObject);
              ^
/usr/include/c++/v1/__functional_base:96:1: note: candidate function [with _Tp = const id]
addressof(__strong _Tp& __x) _NOEXCEPT
^
/usr/include/c++/v1/__functional_base:122:1: note: candidate function [with _Tp = const id]
addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
^
/usr/include/c++/v1/__functional_base:83:1: note: candidate function [with _Tp = const id]
addressof(_Tp& __x) _NOEXCEPT
^
1 error generated.
*** Error code 1
Stop.
make: stopped in /home/chmeee/git-lffoundation/src
Exit 1

此示例中的文件具有声明为std::vector

    std::vector<id> items;

有人可以阐明这个问题吗? 我尝试在std::vector声明中添加显式__strong,但无济于事,但是__unsafe_unretained确实消除了错误。

我正在 FreeBSD -CURRENT 上构建,使用 libc++ 和 clang 3.4 作为基础。

回答我自己的问题,以防其他人感兴趣。 Clang__weak定义为 ARC 的预处理器宏。 然而, FreeBSD 的<sys/cdefs.h>也定义了__weak本身。 我为此找到的解决方法是添加到我的本地<sys/cdefs.h>

#ifndef __weak
#define __weak what_freebsd_defines_ass
#endif

最新更新