diff options
| author | John McCall <rjmccall@apple.com> | 2010-03-31 02:13:20 +0000 | 
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-03-31 02:13:20 +0000 | 
| commit | eae5acbbd01249b7e6fc275a3cca1a6588ab7eee (patch) | |
| tree | c35f280ca5caf4741dbe8bf096e939d3ed47c8ec /clang/lib | |
| parent | da4458e98f54c009116cf4073e065d69fc99e186 (diff) | |
| download | bcm5719-llvm-eae5acbbd01249b7e6fc275a3cca1a6588ab7eee.tar.gz bcm5719-llvm-eae5acbbd01249b7e6fc275a3cca1a6588ab7eee.zip  | |
Fix PR6327:  restore invariants when there's a parse error in an initializer.
llvm-svn: 99980
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/Sema.h | 1 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 35 | 
2 files changed, 36 insertions, 0 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h index 1909607e2d2..72e7f17704d 100644 --- a/clang/lib/Sema/Sema.h +++ b/clang/lib/Sema/Sema.h @@ -828,6 +828,7 @@ public:    virtual void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init);    void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit);    void ActOnUninitializedDecl(DeclPtrTy dcl, bool TypeContainsUndeducedAuto); +  virtual void ActOnInitializerError(DeclPtrTy Dcl);    virtual void SetDeclDeleted(DeclPtrTy dcl, SourceLocation DelLoc);    virtual DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,                                                   DeclPtrTy *Group, diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index b60804a1898..51514e77a2c 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3797,6 +3797,41 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) {    return;  } +/// ActOnInitializerError - Given that there was an error parsing an +/// initializer for the given declaration, try to return to some form +/// of sanity. +void Sema::ActOnInitializerError(DeclPtrTy dcl) { +  // Our main concern here is re-establishing invariants like "a +  // variable's type is either dependent or complete". +  Decl *D = dcl.getAs<Decl>(); +  if (!D || D->isInvalidDecl()) return; + +  VarDecl *VD = dyn_cast<VarDecl>(D); +  if (!VD) return; + +  QualType Ty = VD->getType(); +  if (Ty->isDependentType()) return; + +  // Require a complete type. +  if (RequireCompleteType(VD->getLocation(),  +                          Context.getBaseElementType(Ty), +                          diag::err_typecheck_decl_incomplete_type)) { +    VD->setInvalidDecl(); +    return; +  } + +  // Require an abstract type. +  if (RequireNonAbstractType(VD->getLocation(), Ty, +                             diag::err_abstract_type_in_decl, +                             AbstractVariableType)) { +    VD->setInvalidDecl(); +    return; +  } + +  // Don't bother complaining about constructors or destructors, +  // though. +} +  void Sema::ActOnUninitializedDecl(DeclPtrTy dcl,                                    bool TypeContainsUndeducedAuto) {    Decl *RealDecl = dcl.getAs<Decl>();  | 

