C++ 目标-C++;ARC和C++;容器
我正在尝试编译我的遗留免费libFoundation项目,该项目位于,但在使用clang3.4和libc++时遇到了问题。容器中的ARC似乎不太令人满意,我看到以下错误摘录:C++ 目标-C++;ARC和C++;容器,c++,objective-c,automatic-ref-counting,clang,libc++,C++,Objective C,Automatic Ref Counting,Clang,Libc++,我正在尝试编译我的遗留免费libFoundation项目,该项目位于,但在使用clang3.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/Foundati
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
声明中添加一个显式的\uuuu strong
,但没有效果,但是\uuu unsafe\u unrepaired
确实消除了错误
我在FreeBSD-CURRENT的基础上构建,使用的是base中的libc++和clang 3.4。回答我自己的问题,以防其他人感兴趣
Clang
将\uuu-weak
定义为ARC的预处理器宏。然而,FreeBSD的
也定义了\uu弱
本身。我找到的解决方法是将其添加到我的本地
:
std::vector items
或std::vector items
有效吗?std::vector items代码>适合我。Xcode 5.0.2与clang版本:Apple LLVM版本5.0(clang-500.2.79)(基于LLVM 3.3svn)@GregParker:不,它没有。我尝试了std::vector items
,得到了同样的结果。@BryanChen:谢谢你的尝试。我现在猜测它可能是clang和/或libc++中的一个bug。这很有可能。STL容器只需使用ARC即可。std::vector可能适用于大多数情况,但您发现一些操作需要修复。
std::vector<id> items;
#ifndef __weak
#define __weak what_freebsd_defines_ass
#endif