简体   繁体   中英

Objective-C++ ARC and C++ containers

I'm trying to compile my legacy-free libFoundation project, located at https://github.com/chmeeedalf/lf-foundation but running into problems using clang 3.4 and libc++. It appears something is not happy with ARC in the containers, and I see the following error excerpt:

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

The file in this example has a std::vector declared as:

    std::vector<id> items;

Can someone shed some light onto this problem? I tried adding an explicit __strong in the std::vector declaration, to no avail, however __unsafe_unretained does eliminate the error.

I'm building on FreeBSD -CURRENT, using the libc++ and clang 3.4 that is in base.

Answering my own question, in case others are interested. Clang defines __weak as a preprocessor macro for ARC. However, FreeBSD's <sys/cdefs.h> also defines __weak itself. The workaround I found for this was to add to my local <sys/cdefs.h> :

#ifndef __weak
#define __weak what_freebsd_defines_ass
#endif

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM