[cfe-dev] objc++ enhancements for new c++ features
James Gregurich via cfe-dev
cfe-dev at lists.llvm.org
Wed Mar 21 11:38:40 PDT 2018
>
> I agree it would be great to get ARC-managed pointers working well in std::shared_ptr and std::weak_ptr. The usual subtlety with templates is that __strong doesn't show up in C++ mangling, so it's not straightforward to avoid ODR violations when ARC and MRR translation units are linked together. I think this is solvable, but I doubt it's trivial.
I've come to the conclusion that mixing ARC and non-ARC c++ modules is not viable because of the ODR limitation. Its probably not worth the effort to make it viable. However, all-arc and all-non-arc are both perfectly viable. the use case is the situation where you have a big legacy codebase that will never be made ARC-compatible in its entirety but pieces of it need to work in an ARC process.
the memory header just needs to be changed like so...
template<class _Tp>
class _LIBCPP_TEMPLATE_VIS weak_ptr
{
public:
typedef _Tp element_type;
private:
#if defined(__OBJC__) && __has_feature(objc_arc)
element_type __unsafe_unretained * __ptr_;
#else
element_type* __ptr_;
#endif
__shared_weak_count* __cntrl_;
> I'm skeptical of inventing an ObjC++-specific terse lambda syntax. I'm tempted to let C++ evolve/improve lambda syntax first.
There is no need for any new lambda syntax, and I don't propose any. the compiler already automatically creates a block from standard lambda syntax in a .mm file...all that works great. What is needed is a directive to tell the compiler to generate a function that will invoke a method with a set of correctly typed arguments. basically...tell the compiler to create a lambda function that does a perfect forwarding to the objc method. once you have that, you can easily stuff a selector invocation inside a std::function or std::packaged_task in the usual manner.
something like this...
std::packaged_task< int (cTest*, NSString*) > tmpTask( @lambda( -[cMyClass methodUsingString:] ) );
auto tmpCFuture = tmpTask.get_future();
auto tmpCPtr = [[[cTest alloc] init] autorelease];
tmpTask( tmpCPtr, @"hello world" );
auto tmpResult = tmpCFuture.get();
The objc++ compiler works pretty well and is very thorough in integrating the objc world into the c++ world. there are just holes in its capabilities here and there that need to be filled.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180321/4be3956e/attachment.html>
More information about the cfe-dev
mailing list