[Sema] Don't crash when diagnosing hack in libstdc++

While working around a bug in certain standard library implementations,
we would try to diagnose the issue so that library implementors would
fix their code.  However, we assumed an entity being initialized was
a non-static data member subobject when other circumstances are
possible.

This fixes PR24526.

llvm-svn: 245675
This commit is contained in:
David Majnemer 2015-08-21 06:44:10 +00:00
parent 84cfb1dcde
commit 9588a95b82
2 changed files with 8 additions and 4 deletions

View File

@ -443,8 +443,11 @@ ExprResult InitListChecker::PerformEmptyInit(Sema &SemaRef,
if (!VerifyOnly) {
SemaRef.Diag(CtorDecl->getLocation(),
diag::warn_invalid_initializer_from_system_header);
SemaRef.Diag(Entity.getDecl()->getLocation(),
diag::note_used_in_initialization_here);
if (Entity.getKind() == InitializedEntity::EK_Member)
SemaRef.Diag(Entity.getDecl()->getLocation(),
diag::note_used_in_initialization_here);
else if (Entity.getKind() == InitializedEntity::EK_ArrayElement)
SemaRef.Diag(Loc, diag::note_used_in_initialization_here);
}
}
}

View File

@ -9,7 +9,7 @@ namespace __debug {
template <class T>
class vector {
public:
explicit vector() {} // expected-warning{{should not be explicit}}
explicit vector() {} // expected-warning 2 {{should not be explicit}}
};
}
}
@ -19,5 +19,6 @@ public:
#include __FILE__
struct { int a, b; std::__debug::vector<int> c; } e[] = { {1, 1} }; // expected-note{{used in initialization here}}
// expected-warning@+1 {{expression with side effects has no effect in an unevaluated context}}
decltype(new std::__debug::vector<int>[1]{}) x; // expected-note{{used in initialization here}}
#endif