Skip to content

Commit

Permalink
fix(cxx_indexer): handle list-init on incomplete types (#4584)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahms committed Jul 13, 2020
1 parent bf8c25a commit 0bcb51e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion kythe/cxx/indexer/cxx/IndexerASTHooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,20 @@ std::string DumpString(const T& val, Tail&&... tail) {
return s;
}

bool IsCompleteAggregateType(clang::QualType Type) {
if (Type.isNull()) {
return false;
}
Type = Type.getCanonicalType();
return !Type->isIncompleteType() && Type->isAggregateType();
}

llvm::SmallVector<const clang::Decl*, 5> GetInitExprDecls(
const clang::InitListExpr* ILE) {
CHECK(ILE->isSemanticForm());
QualType Type = ILE->getType();
// Ignore non-aggregate and copy initialization.
if (Type.isNull() || !Type->isAggregateType() || ILE->isTransparent()) {
if (!IsCompleteAggregateType(Type) || ILE->isTransparent()) {
return {};
}
if (const clang::FieldDecl* Field = ILE->getInitializedFieldInUnion()) {
Expand Down
8 changes: 8 additions & 0 deletions kythe/cxx/indexer/cxx/testdata/rec/rec_agg_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ struct Default {
Default();
};

//- @I defines/binding StructI
struct I;

//- @S defines/binding StructS
struct S {
//- @a defines/binding FieldA
Expand Down Expand Up @@ -49,6 +52,8 @@ struct V {

S FromValue();

const I& ReturnsIncomplete();

template <typename...T>
void fn(T&&...);

Expand Down Expand Up @@ -91,4 +96,7 @@ void f() {
//- !{ @#0"}" ref/init _ }
//- !{ @#1"}" ref/init _ }
V v{{1}, 2};

//- @#0I ref StructI
const I& i{ReturnsIncomplete()};
}

0 comments on commit 0bcb51e

Please sign in to comment.