[cfe-commits] r51265 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/SemaInit.cpp
Eli Friedman
eli.friedman at gmail.com
Mon May 19 13:12:18 PDT 2008
Author: efriedma
Date: Mon May 19 15:12:18 2008
New Revision: 51265
URL: http://llvm.org/viewvc/llvm-project?rev=51265&view=rev
Log:
Add errors for some illegal constructs (specifically, "int a = {{3}};"
and "int a = {};"). I'll adjust the tests in a bit.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/lib/Sema/SemaInit.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=51265&r1=51264&r2=51265&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Mon May 19 15:12:18 2008
@@ -745,6 +745,10 @@
"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)")
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=51265&r1=51264&r2=51265&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Mon May 19 15:12:18 2008
@@ -109,7 +109,7 @@
// 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 @@
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 @@
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;
}
}
More information about the cfe-commits
mailing list