[cfe-dev] Objective-C++11 literal types
Douglas Gregor
dgregor at apple.com
Sat Dec 3 12:52:12 PST 2011
On Dec 1, 2011, at 8:22 PM, Richard Smith wrote:
> On Fri, December 2, 2011 04:09, John McCall wrote:
>> On Dec 1, 2011, at 4:23 PM, Richard Smith wrote:
>>> I was surprised to find this in AST::Type::isLiteralType:
>>>
>>>
>>> // Objective-C lifetime types are not literal types.
>>> if (BaseTy->isObjCRetainableType()) return false;
>>>
>>> This is strange, because we do support constant expression evaluation of
>>> Objective-C lifetime types (outside C++11).
>>>
>>>
>>> So which is correct? Should lifetime types be permitted as literal types,
>>> or should they not be permitted as the type of globals in (Objective-)C? Or
>>> is there some reason why C++11 should treat them differently from other
>>> languages?
>>
>> I don't know the reasoning for that change, but I would assume it's
>> supposed to apply to ownership-qualified types under ARC, i.e. types with a
>> non-trivial ObjCLifetime qualifier, because such types generally require extra
>> operations which need to be performed at runtime. However, I don't know that
>> that's actually correct, because any object of such a type that can be
>> constant-evaluated must also be statically allocated, which means that retains
>> and releases can be completely ignored. That might be a lot of complexity to
>> get right, though.
>
> We allow these types to be subject to constant initialization in (Objective-)
> C and C++98 already. If there is extra complexity, handling it in a
> C++11-specific fashion seems wrong unless the complexity is C++11-specific --
> which I don't think it is. Any objection to my removing this check?
No objection. I (incorrectly) added this check a while ago, thinking that we wouldn't ever be able to do constant-evaluation for ownership-qualified types under ARC.
- Doug
More information about the cfe-dev
mailing list