簡體   English   中英

Objective-C ++ ARC和C ++容器

[英]Objective-C++ ARC and C++ containers

我正在嘗試編譯位於https://github.com/chmeeedalf/lf-foundation的無遺留libFoundation項目,但是使用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確實消除了錯誤。

我使用基於libc ++和clang 3.4的FreeBSD -CURRENT構建。

如果其他人有興趣,請回答我自己的問題。 Clang__weak定義為ARC的預處理器宏。 但是,FreeBSD的<sys/cdefs.h>也定義了__weak本身。 我為此找到的解決方法是將其添加到本地<sys/cdefs.h>

#ifndef __weak
#define __weak what_freebsd_defines_ass
#endif

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM