diff options
| author | Anders Carlsson <andersca@mac.com> | 2009-06-24 00:10:43 +0000 |
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2009-06-24 00:10:43 +0000 |
| commit | 946b86d91abfe0f771a962df8abdb676ab6133fc (patch) | |
| tree | a219a548ae98fe140d3f99b2bb60ea0c8dd7bf63 /clang/lib | |
| parent | 5a495fea076baefce2901adda01bd6103b2bf2c1 (diff) | |
| download | bcm5719-llvm-946b86d91abfe0f771a962df8abdb676ab6133fc.tar.gz bcm5719-llvm-946b86d91abfe0f771a962df8abdb676ab6133fc.zip | |
[class.local] p1 and p3. Also, add back the xcodeproj file.
llvm-svn: 74027
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/Sema.h | 7 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 43 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 1 |
3 files changed, 36 insertions, 15 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h index fe13b56eb0f..23e12d80c98 100644 --- a/clang/lib/Sema/Sema.h +++ b/clang/lib/Sema/Sema.h @@ -1377,9 +1377,10 @@ public: bool HasTrailingLParen, const CXXScopeSpec &SS, bool isAddressOfOperand); - DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc, - bool TypeDependent, bool ValueDependent, - const CXXScopeSpec *SS = 0); + OwningExprResult BuildDeclRefExpr(NamedDecl *D, QualType Ty, + SourceLocation Loc, bool TypeDependent, + bool ValueDependent, + const CXXScopeSpec *SS = 0); VarDecl *BuildAnonymousStructUnionMemberPath(FieldDecl *Field, llvm::SmallVectorImpl<FieldDecl *> &Path); OwningExprResult diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 56d3bfe690b..0f73f9e9adf 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -623,17 +623,36 @@ Sema::OwningExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc, /// BuildDeclRefExpr - Build either a DeclRefExpr or a /// QualifiedDeclRefExpr based on whether or not SS is a /// nested-name-specifier. -DeclRefExpr * +Sema::OwningExprResult Sema::BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc, bool TypeDependent, bool ValueDependent, const CXXScopeSpec *SS) { + + if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { + if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext)) { + if (const FunctionDecl *FD = MD->getParent()->isLocalClass()) { + if (VD->hasLocalStorage() && VD->getDeclContext() != CurContext) { + Diag(Loc, diag::err_reference_to_local_var_in_enclosing_function) + << D->getIdentifier() << FD->getDeclName(); + Diag(D->getLocation(), diag::note_local_variable_declared_here) + << D->getIdentifier(); + return ExprError(); + } + } + } + } + MarkDeclarationReferenced(Loc, D); + + Expr *E; if (SS && !SS->isEmpty()) { - return new (Context) QualifiedDeclRefExpr(D, Ty, Loc, TypeDependent, - ValueDependent, SS->getRange(), + E = new (Context) QualifiedDeclRefExpr(D, Ty, Loc, TypeDependent, + ValueDependent, SS->getRange(), static_cast<NestedNameSpecifier *>(SS->getScopeRep())); } else - return new (Context) DeclRefExpr(D, Ty, Loc, TypeDependent, ValueDependent); + E = new (Context) DeclRefExpr(D, Ty, Loc, TypeDependent, ValueDependent); + + return Owned(E); } /// getObjectForAnonymousRecordDecl - Retrieve the (unnamed) field or @@ -968,7 +987,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, // The pointer is type- and value-dependent if it points into something // dependent. bool Dependent = DC->isDependentContext(); - return Owned(BuildDeclRefExpr(D, DType, Loc, Dependent, Dependent, SS)); + return BuildDeclRefExpr(D, DType, Loc, Dependent, Dependent, SS); } } } @@ -1061,11 +1080,11 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, // Make the DeclRefExpr or BlockDeclRefExpr for the decl. if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) - return Owned(BuildDeclRefExpr(Ovl, Context.OverloadTy, Loc, - false, false, SS)); + return BuildDeclRefExpr(Ovl, Context.OverloadTy, Loc, + false, false, SS); else if (TemplateDecl *Template = dyn_cast<TemplateDecl>(D)) - return Owned(BuildDeclRefExpr(Template, Context.OverloadTy, Loc, - false, false, SS)); + return BuildDeclRefExpr(Template, Context.OverloadTy, Loc, + false, false, SS); ValueDecl *VD = cast<ValueDecl>(D); // Check whether this declaration can be used. Note that we suppress @@ -1113,7 +1132,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, QualType NoProtoType = T; if (const FunctionProtoType *Proto = T->getAsFunctionProtoType()) NoProtoType = Context.getFunctionNoProtoType(Proto->getResultType()); - return Owned(BuildDeclRefExpr(VD, NoProtoType, Loc, false, false, SS)); + return BuildDeclRefExpr(VD, NoProtoType, Loc, false, false, SS); } } @@ -1194,8 +1213,8 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, } } - return Owned(BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(), Loc, - TypeDependent, ValueDependent, SS)); + return BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(), Loc, + TypeDependent, ValueDependent, SS); } Sema::OwningExprResult Sema::ActOnPredefinedExpr(SourceLocation Loc, diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 914839cbf79..5a91496db1a 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -835,6 +835,7 @@ static bool IsReturnCopyElidable(ASTContext &Ctx, QualType RetType, Action::OwningStmtResult Sema::ActOnReturnStmt(SourceLocation ReturnLoc, FullExprArg rex) { + bool RetValExprIsValid = !rex->isInvalid(); Expr *RetValExp = rex->takeAs<Expr>(); if (CurBlock) return ActOnBlockReturnStmt(ReturnLoc, RetValExp); |

