[cfe-commits] r46869 - in /cfe/trunk: Sema/SemaDecl.cpp include/clang/Basic/DiagnosticKinds.def test/Sema/init.c
Eli Friedman
eli.friedman at gmail.com
Thu Feb 7 16:48:24 PST 2008
Author: efriedma
Date: Thu Feb 7 18:48:24 2008
New Revision: 46869
URL: http://llvm.org/viewvc/llvm-project?rev=46869&view=rev
Log:
Improve diagnostic for illegal array initialization.
Modified:
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/test/Sema/init.c
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=46869&r1=46868&r2=46869&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Thu Feb 7 18:48:24 2008
@@ -659,6 +659,12 @@
// FIXME: Handle wide strings
if (StringLiteral *strLiteral = IsStringLiteralInit(Init, DeclType))
return CheckStringLiteralInit(strLiteral, DeclType);
+
+ if (DeclType->isArrayType())
+ return Diag(Init->getLocStart(),
+ diag::err_array_init_list_required,
+ Init->getSourceRange());
+
return CheckSingleInitializer(Init, DeclType);
}
unsigned newIndex = 0;
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=46869&r1=46868&r2=46869&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Thu Feb 7 18:48:24 2008
@@ -653,6 +653,8 @@
"'extern' variable has an initializer")
DIAG(err_variable_object_no_init, ERROR,
"variable-sized object may not be initialized")
+DIAG(err_array_init_list_required, ERROR,
+ "initialization with \"{...}\" expected for array")
DIAG(warn_excess_initializers, WARNING,
"excess elements in array initializer")
DIAG(err_excess_initializers_in_char_array_initializer, ERROR,
Modified: cfe/trunk/test/Sema/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/init.c?rev=46869&r1=46868&r2=46869&view=diff
==============================================================================
--- cfe/trunk/test/Sema/init.c (original)
+++ cfe/trunk/test/Sema/init.c Thu Feb 7 18:48:24 2008
@@ -13,3 +13,7 @@
void *g = &x;
int *h = &x;
+int test() {
+int a[10];
+int b[10] = a; // expected-error {{initialization with "{...}" expected}}
+}
More information about the cfe-commits
mailing list