Fix a crash-on-invalid where the constant evaluator would try to

evaluate certain expressions involving invalidly-defined classes.

llvm-svn: 155645
This commit is contained in:
John McCall 2012-04-26 18:10:01 +00:00
parent c32e5c9bc2
commit 3c79d88f06
2 changed files with 12 additions and 0 deletions

View File

@ -3408,6 +3408,7 @@ static bool HandleClassZeroInitialization(EvalInfo &Info, const Expr *E,
bool RecordExprEvaluator::ZeroInitialization(const Expr *E) {
const RecordDecl *RD = E->getType()->castAs<RecordType>()->getDecl();
if (RD->isInvalidDecl()) return false;
if (RD->isUnion()) {
// C++11 [dcl.init]p5: If T is a (possibly cv-qualified) union type, the
// object's first non-static named data member is zero-initialized
@ -3470,6 +3471,8 @@ bool RecordExprEvaluator::VisitInitListExpr(const InitListExpr *E) {
return false;
const RecordDecl *RD = E->getType()->castAs<RecordType>()->getDecl();
if (RD->isInvalidDecl()) return false;
const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(RD);
if (RD->isUnion()) {
@ -3528,6 +3531,8 @@ bool RecordExprEvaluator::VisitInitListExpr(const InitListExpr *E) {
bool RecordExprEvaluator::VisitCXXConstructExpr(const CXXConstructExpr *E) {
const CXXConstructorDecl *FD = E->getConstructor();
if (FD->isInvalidDecl() || FD->getParent()->isInvalidDecl()) return false;
bool ZeroInit = E->requiresZeroInitialization();
if (CheckTrivialDefaultConstructor(Info, E->getExprLoc(), FD, ZeroInit)) {
// If we've already performed zero-initialization, we're already done.

View File

@ -117,3 +117,10 @@ namespace FloatConvert {
typedef int a[(int)42.997];
typedef int b[(int)4e10]; // expected-warning {{variable length}} expected-error {{variable length}}
}
// PR12626
namespace test3 {
struct X; // expected-note {{forward declaration of 'test3::X'}}
struct Y { bool b; X x; }; // expected-error {{field has incomplete type 'test3::X'}}
int f() { return Y().b; }
}