diff options
-rw-r--r-- | Sema/SemaDecl.cpp | 8 | ||||
-rw-r--r-- | test/Sema/invalid-decl.c | 7 |
2 files changed, 14 insertions, 1 deletions
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index ee3cc7a88c..db10de2a44 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -635,8 +635,14 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) { void Sema::AddInitializerToDecl(DeclTy *dcl, ExprTy *init) { Decl *RealDecl = static_cast<Decl *>(dcl); Expr *Init = static_cast<Expr *>(init); + assert(Init && "missing initializer"); - assert((RealDecl && Init) && "missing decl or initializer"); + // If there is no declaration, there was an error parsing it. Just ignore + // the initializer. + if (RealDecl == 0) { + delete Init; + return; + } VarDecl *VDecl = dyn_cast<VarDecl>(RealDecl); if (!VDecl) { diff --git a/test/Sema/invalid-decl.c b/test/Sema/invalid-decl.c new file mode 100644 index 0000000000..bd9302b206 --- /dev/null +++ b/test/Sema/invalid-decl.c @@ -0,0 +1,7 @@ + +void test() { + char = 4; // expected-error {{expected identifier}} expected-error{{declarator requires an identifier}} + +} + + |