From: Eli Friedman Date: Fri, 8 Feb 2008 00:48:24 +0000 (+0000) Subject: Improve diagnostic for illegal array initialization. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a312ce2bdaaff62f21d560bad6cb0519f613d334;p=clang Improve diagnostic for illegal array initialization. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46869 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 00776912b0..b81f3fe53e 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -659,6 +659,12 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType) { // 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; diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 7e31847e86..3a8c04c9df 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -653,6 +653,8 @@ DIAG(warn_extern_init, WARNING, "'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, diff --git a/test/Sema/init.c b/test/Sema/init.c index bbad04cd73..9d0d7335fe 100644 --- a/test/Sema/init.c +++ b/test/Sema/init.c @@ -13,3 +13,7 @@ extern int x; void *g = &x; int *h = &x; +int test() { +int a[10]; +int b[10] = a; // expected-error {{initialization with "{...}" expected}} +}