mirror of
https://github.com/intel/llvm.git
synced 2026-01-26 12:26:52 +08:00
Add some more checking for compound literals.
llvm-svn: 51300
This commit is contained in:
@@ -738,7 +738,20 @@ ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
|
||||
//assert((InitExpr != 0) && "ActOnCompoundLiteral(): missing expression");
|
||||
Expr *literalExpr = static_cast<Expr*>(InitExpr);
|
||||
|
||||
// FIXME: add more semantic analysis (C99 6.5.2.5).
|
||||
if (literalType->isArrayType()) {
|
||||
if (literalType->getAsVariableArrayType())
|
||||
return Diag(LParenLoc,
|
||||
diag::err_variable_object_no_init,
|
||||
SourceRange(LParenLoc,
|
||||
literalExpr->getSourceRange().getEnd()));
|
||||
} else if (literalType->isIncompleteType()) {
|
||||
return Diag(LParenLoc,
|
||||
diag::err_typecheck_decl_incomplete_type,
|
||||
literalType.getAsString(),
|
||||
SourceRange(LParenLoc,
|
||||
literalExpr->getSourceRange().getEnd()));
|
||||
}
|
||||
|
||||
if (CheckInitializerTypes(literalExpr, literalType))
|
||||
return true;
|
||||
|
||||
|
||||
@@ -21,4 +21,8 @@ int main(int argc, char **argv) {
|
||||
fooFunc(&(struct foo){ 1, 2 });
|
||||
}
|
||||
|
||||
|
||||
struct Incomplete;
|
||||
struct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{variable has incomplete type}}
|
||||
void IncompleteFunc(unsigned x) {
|
||||
struct Incomplete* I2 = (struct foo[x]){1, 2, 3}; // -expected-error {{variable-sized object may not be initialized}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user