diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-02-27 04:17:12 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-02-27 04:17:12 +0000 |
commit | 3b8a36aea7c4d93c5f7cd772c5c9cde28647b3f0 (patch) | |
tree | 4ae8540158c8067aa8b27a2e68abcda00d307d92 /lib/Sema/SemaDecl.cpp | |
parent | 0de40af3a3aa14e3854c0eafeabd08f6762801f9 (diff) |
Fix minor memory leak. Add comment describing what we need to do for
strict constant initializer checking.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65612 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index b3f2500539..6dbb66a4b7 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2020,6 +2020,14 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, } bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) { + // FIXME: Need strict checking. In C89, we need to check for + // any assignment, increment, decrement, function-calls, or + // commas outside of a sizeof. In C99, it's the same list, + // except that the aforementioned are allowed in unevaluated + // expressions. Everything else falls under the + // "may accept other forms of constant expressions" exception. + // (We never end up here for C++, so the constant expression + // rules there don't matter.) if (Init->isConstantInitializer(Context)) return false; Diag(Init->getExprLoc(), diag::err_init_element_not_constant) @@ -2036,22 +2044,23 @@ void Sema::AddInitializerToDecl(DeclTy *dcl, ExprArg init) { /// initialization rather than copy initialization. void Sema::AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit) { Decl *RealDecl = static_cast<Decl *>(dcl); - Expr *Init = static_cast<Expr *>(init.release()); - assert(Init && "missing initializer"); - // If there is no declaration, there was an error parsing it. Just ignore // the initializer. - if (RealDecl == 0) { - Init->Destroy(Context); + if (RealDecl == 0) return; - } VarDecl *VDecl = dyn_cast<VarDecl>(RealDecl); if (!VDecl) { Diag(RealDecl->getLocation(), diag::err_illegal_initializer); RealDecl->setInvalidDecl(); return; - } + } + + // Take ownership of the expression, now that we're sure we have somewhere + // to put it. + Expr *Init = static_cast<Expr *>(init.release()); + assert(Init && "missing initializer"); + // Get the decls type and save a reference for later, since // CheckInitializerTypes may change it. QualType DclT = VDecl->getType(), SavT = DclT; |