[SemaCXX] Fix ICE with structure bindings to members of template
authorNicolas Lesser <blitzrakete@gmail.com>
Sun, 27 Jan 2019 19:19:59 +0000 (19:19 +0000)
committerNicolas Lesser <blitzrakete@gmail.com>
Sun, 27 Jan 2019 19:19:59 +0000 (19:19 +0000)
commit0276d12426c03f493afa4958136ffc8add7c40f3
tree7413b3e4b50268a9aacd89e4886eea25669b1afc
parent1dc4e01cbfbdc612203a98b6d2a6ffe37bbd3c90
[SemaCXX] Fix ICE with structure bindings to members of template

Summary:
Trying to use structure binding with a structure that doesn't implement
std::tuple_size, should unpack the data members. When the struct is a
template though, clang might hit an assertion (if the type has not been
completed before), because CXXRecordDecl::DefinitionData is nullptr.

This commit fixes the problem by completing the type while trying to
decompose the structured binding.

The ICE happens in real world code, for example, when trying to iterate
a protobuf generated map with a range-based for loop and structure
bindings (because google::protobuf::MapPair is a template and doesn't
support std::tuple_size).

Reported-by: nicholas.sun@nlsun.com
Patch by Daniele Di Proietto

Reviewers: #clang, rsmith

Reviewed By: #clang, rsmith

Subscribers: cpplearner, Rakete1111, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D56974

llvm-svn: 352323
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/cxx1z-decomposition.cpp