Add errors for some illegal constructs (specifically, "int a = {{3}};"

and "int a = {};").  I'll adjust the tests in a bit.

llvm-svn: 51265
This commit is contained in:
Eli Friedman 2008-05-19 20:12:18 +00:00
parent 6e70830af9
commit feb4cc1c6a
2 changed files with 18 additions and 10 deletions

View File

@ -745,6 +745,10 @@ DIAG(warn_initializer_string_for_char_array_too_long, WARNING,
"initializer-string for char array is too long")
DIAG(warn_braces_around_scalar_init, WARNING,
"braces around scalar initializer")
DIAG(err_many_braces_around_scalar_init, ERROR,
"too many braces around scalar initializer")
DIAG(err_empty_scalar_initializer, ERROR,
"scalar initializer cannot be empty")
DIAG(err_illegal_initializer, ERROR,
"illegal initializer (only variables can be initialized)")

View File

@ -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;
}
}