This is an archive of the discontinued LLVM Phabricator instance.

[Sema][C++1z] Ensure structured binding's bindings in dependent foreach have non-null type
ClosedPublic

Authored by erik.pilkington on Jun 11 2017, 6:30 PM.

Details

Summary

A DecompositionDecls' bindings have a null type until the initializer is attached, if the initializer is dependent, then the bindings should be set to have dependent type. For non-foreach bindings, this is done in Sema::CheckCompleteDecompositionDeclaration(), this patch ensures that this is done to bindings in a foreach as well. Fixes PR32172.

Thanks for taking a look!
Erik

Diff Detail

Event Timeline

rsmith accepted this revision.Jun 11 2017, 6:53 PM

LGTM

This revision is now accepted and ready to land.Jun 11 2017, 6:53 PM
This revision was automatically updated to reflect the committed changes.
bebuch reopened this revision.Jun 16 2017, 10:50 AM
bebuch added a subscriber: bebuch.

I believe this patch is incomplete, I get a very odd warning:

struct A{
    int x;
};

template < typename >
struct B{
    A data_[1];

    void f(){
        for(auto [x]: data_){
            (void)x;
        }
    }
};

int main(){
	B< int > v;
	v.f();
}
$ clang++ -std=c++1z -Wall clang_fail.cpp                                                                                                                                                                                
clang_fail.cpp:10:18: warning: unused variable '' [-Wunused-variable]                                                                                                                                                                                                 
        for(auto [x]: data_){                                                                                                                                                                                                                                         
                 ^                                                                                                                                                                                                                                                    
clang_fail.cpp:18:4: note: in instantiation of member function 'B<int>::f' requested here                                                                                                                                                                             
        v.f();                                                                                                                                                                                                                                                        
          ^                                                                                                                                                                                                                                                           
1 warning generated.

unused variable ''? An unnamed variable, that's odd ;-)

Nevertheless, thanks for what is already done! Great that I can use structured bindings without fear to crash now! :-)

This revision is now accepted and ready to land.Jun 16 2017, 10:50 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 7 2019, 5:58 AM