From: Anders Carlsson Date: Sun, 7 Dec 2008 00:49:48 +0000 (+0000) Subject: Pass the VLA size expr range to the VLA diags X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7fd1df2a87729059a1589c47606f7a43f531c39f;p=clang Pass the VLA size expr range to the VLA diags git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60645 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 4d01a2d52c..f125cb270e 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1928,17 +1928,27 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) { QualType T = IDecl->getType(); if (T->isVariableArrayType()) { + const VariableArrayType *VAT = + cast(T.getUnqualifiedType()); + + // FIXME: This won't give the correct result for + // int a[10][n]; + SourceRange SizeRange = VAT->getSizeExpr()->getSourceRange(); if (IDecl->isFileVarDecl()) { - Diag(IDecl->getLocation(), diag::err_vla_decl_in_file_scope); + Diag(IDecl->getLocation(), diag::err_vla_decl_in_file_scope) << + SizeRange; + IDecl->setInvalidDecl(); } else { // C99 6.7.5.2p2: If an identifier is declared to be an object with // static storage duration, it shall not have a variable length array. if (IDecl->getStorageClass() == VarDecl::Static) { - Diag(IDecl->getLocation(), diag::err_vla_decl_has_static_storage); + Diag(IDecl->getLocation(), diag::err_vla_decl_has_static_storage) + << SizeRange; IDecl->setInvalidDecl(); } else if (IDecl->getStorageClass() == VarDecl::Extern) { - Diag(IDecl->getLocation(), diag::err_vla_decl_has_extern_linkage); + Diag(IDecl->getLocation(), diag::err_vla_decl_has_extern_linkage) + << SizeRange; IDecl->setInvalidDecl(); } }