diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-06-03 01:05:37 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-06-03 01:05:37 +0000 |
commit | b45a4d217cf1513b14a143143a2c3af8738a3cd7 (patch) | |
tree | 7cb2ca1650ef26c3b92916aeefc485a42fab7cbc /lib/Sema/JumpDiagnostics.cpp | |
parent | 4e43dec4df9d7dd8e07b47bb15967f1b733a9bc6 (diff) |
Fix a couple of bugs where jump diagnostics would not notice that a variable
has an initializer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183092 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/JumpDiagnostics.cpp')
-rw-r--r-- | lib/Sema/JumpDiagnostics.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/Sema/JumpDiagnostics.cpp b/lib/Sema/JumpDiagnostics.cpp index 8e446f8b9b..d3de173276 100644 --- a/lib/Sema/JumpDiagnostics.cpp +++ b/lib/Sema/JumpDiagnostics.cpp @@ -172,10 +172,6 @@ static ScopePair GetDiagForGotoScopeDecl(ASTContext &Context, const Decl *D) { if (EWC) Init = EWC->getSubExpr(); - // FIXME: Why are we looking through reference initialization? - // This causes us to incorrectly accept invalid code such as: - // struct S { int n; }; - // int f() { goto x; S &&s = S(); x: return x.n; } const MaterializeTemporaryExpr *M = NULL; Init = Init->findMaterializedTemporary(M); @@ -184,7 +180,7 @@ static ScopePair GetDiagForGotoScopeDecl(ASTContext &Context, const Decl *D) { Init = Init->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments); QualType QT = Init->getType(); - if (QT.isNull() || !CommaLHSs.empty()) + if (QT.isNull()) return ScopePair(diag::note_protected_by_variable_init, 0); const Type *T = QT.getTypePtr(); @@ -203,7 +199,11 @@ static ScopePair GetDiagForGotoScopeDecl(ASTContext &Context, const Decl *D) { if (const CXXConstructExpr *cce = dyn_cast<CXXConstructExpr>(Init)) { const CXXConstructorDecl *ctor = cce->getConstructor(); - if (ctor->isTrivial() && ctor->isDefaultConstructor()) { + // For a variable declared without an initializer, we will have + // call-style initialization and the initializer will be the + // CXXConstructExpr with no intervening nodes. + if (ctor->isTrivial() && ctor->isDefaultConstructor() && + VD->getInit() == Init && VD->getInitStyle() == VarDecl::CallInit) { if (OutDiag) InDiag = diag::note_protected_by_variable_nontriv_destructor; else if (!Record->isPOD()) |