[cfe-commits] r140457 - in /cfe/trunk: include/clang/Sema/Initialization.h include/clang/Sema/Overload.h include/clang/Sema/Sema.h lib/Sema/SemaExpr.cpp lib/Sema/SemaInit.cpp lib/Sema/SemaOverload.cpp

Douglas Gregor dgregor at apple.com
Wed Oct 5 10:49:39 PDT 2011


Sent from my iPhone

On Oct 2, 2011, at 3:47 AM, Sebastian Redl <sebastian.redl at getdesigned.at> wrote:

> On 09/26/2011 04:58 PM, Douglas Gregor wrote:
>> On Sep 24, 2011, at 10:48 AM, Sebastian Redl wrote:
>> 
>>> Author: cornedbee
>>> Date: Sat Sep 24 12:48:00 2011
>>> New Revision: 140457
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=140457&view=rev
>>> Log:
>>> Give InitListChecker a verification-only mode, where it neither emits diagnostics nor
>>> builds a semantic (structured) initializer list, just reports on whether it can match
>>> the given list to the target type.
>>> Use this mode for doing init list checking in the initial step of initialization, which
>>> will eventually allow us to do overload resolution based on the outcome.
>> Cool. Comments below.
>> 
>>>   // @brief Retrieves the fully-structured initializer list used for
>>> @@ -450,8 +451,9 @@
>>> 
>>> 
>>> InitListChecker::InitListChecker(Sema&S, const InitializedEntity&Entity,
>>> -                                 InitListExpr *IL, QualType&T)
>>> -  : SemaRef(S) {
>>> +                                 InitListExpr *IL, QualType&T,
>>> +                                 bool VerifyOnly)
>>> +  : SemaRef(S), VerifyOnly(VerifyOnly) {
>>>   hadError = false;
>>> 
>>>   unsigned newIndex = 0;
>>> @@ -462,7 +464,7 @@
>>>                         FullyStructuredList, newStructuredIndex,
>>>                         /*TopLevelObject=*/true);
>>> 
>>> -  if (!hadError) {
>>> +  if (!hadError&&  !VerifyOnly) {
>>>     bool RequiresSecondPass = false;
>>>     FillInValueInitializations(Entity, FullyStructuredList, RequiresSecondPass);
>> It seems like we do still need to check the value initializations (to make sure there is a suitable default constructor for members that haven't been initialized), although we don't want to build anything.
>> 
> It turns out this is much harder than expected. I cannot just extend the verify-only mode to FillInValueInitializers because it is built with the assumption of having a fully structured init list to traverse.
> It's reasonably easy to check value initialization for entries left out at the end of the init list during the primary checker run, i.e.
> NoDefaultCtor array[2] = { 1 };
> But without the structured initializer list, I have no idea how to find holes left by designated initializers, i.e.
> NoDefaultCtor array{2] = { [1] = 1 };

That is tricky. I don't see any solution that doesn't involve building the structured init list (or something like it), but we really don't want to burn memory on building the structured init list twice. 



More information about the cfe-commits mailing list