diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2008-02-08 00:48:24 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2008-02-08 00:48:24 +0000 |
commit | a312ce2bdaaff62f21d560bad6cb0519f613d334 (patch) | |
tree | 9780cf9b29618dbbdbc8b88ec198cf3aa2119991 | |
parent | dfab6cb59a703f2ce4d58371652ce879f4c85a09 (diff) |
Improve diagnostic for illegal array initialization.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46869 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Sema/SemaDecl.cpp | 6 | ||||
-rw-r--r-- | include/clang/Basic/DiagnosticKinds.def | 2 | ||||
-rw-r--r-- | test/Sema/init.c | 4 |
3 files changed, 12 insertions, 0 deletions
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}} +} |