diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2008-05-19 20:12:18 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2008-05-19 20:12:18 +0000 |
commit | feb4cc1c6ae53c86d030c56fe8704fb962b27cca (patch) | |
tree | a36eea609259063289e5d6c3e4140af2b6d689a4 /clang/lib/Sema/SemaInit.cpp | |
parent | 6e70830af99b369babd0a8b05c7b2113e7d6223d (diff) | |
download | bcm5719-llvm-feb4cc1c6ae53c86d030c56fe8704fb962b27cca.tar.gz bcm5719-llvm-feb4cc1c6ae53c86d030c56fe8704fb962b27cca.zip |
Add errors for some illegal constructs (specifically, "int a = {{3}};"
and "int a = {};"). I'll adjust the tests in a bit.
llvm-svn: 51265
Diffstat (limited to 'clang/lib/Sema/SemaInit.cpp')
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index fb5329cfbb0..94ddd0428dc 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -109,7 +109,7 @@ void InitListChecker::CheckExplicitInitList(InitListExpr *IList, QualType &T, // We have leftover initializers if (IList->getNumInits() > 0 && SemaRef->IsStringLiteralInit(IList->getInit(Index), T)) { - // Special-case; this could be confusing + // Special-case SemaRef->Diag(IList->getInit(Index)->getLocStart(), diag::err_excess_initializers_in_char_array_initializer, IList->getInit(Index)->getSourceRange()); @@ -173,17 +173,27 @@ void InitListChecker::CheckScalarType(InitListExpr *IList, QualType &DeclType, if (Index < IList->getNumInits()) { Expr* expr = IList->getInit(Index); if (isa<InitListExpr>(expr)) { - // FIXME: Print error about too many braces + SemaRef->Diag(IList->getLocStart(), + diag::err_many_braces_around_scalar_init, + IList->getSourceRange()); + hadError = true; + ++Index; + return; } Expr *savExpr = expr; // Might be promoted by CheckSingleInitializer. if (SemaRef->CheckSingleInitializer(expr, DeclType)) - hadError |= true; // types weren't compatible. + hadError = true; // types weren't compatible. else if (savExpr != expr) // The type was promoted, update initializer list. IList->setInit(Index, expr); ++Index; + } else { + SemaRef->Diag(IList->getLocStart(), + diag::err_empty_scalar_initializer, + IList->getSourceRange()); + hadError = true; + return; } - // FIXME: Should an error be reported for empty initializer list + scalar? } void InitListChecker::CheckVectorType(InitListExpr *IList, QualType DeclType, @@ -210,12 +220,6 @@ void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType, SemaRef->IsStringLiteralInit(IList->getInit(Index), DeclType)) { SemaRef->CheckStringLiteralInit(lit, DeclType); ++Index; -#if 0 - if (IList->isExplicit() && Index < IList->getNumInits()) { - // We have leftover initializers; warn - - } -#endif return; } } |