Skip to content

Commit 576f888

Browse files
committed
Reject incomplete types and vlas
1 parent 548eadb commit 576f888

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3702,6 +3702,10 @@ def err_conflicting_codeseg_attribute : Error<
37023702
def warn_duplicate_codeseg_attribute : Warning<
37033703
"duplicate code segment specifiers">, InGroup<Section>;
37043704

3705+
def err_expansion_stmt_vla : Error<
3706+
"cannot expand variable length array type %0">;
3707+
def err_expansion_stmt_incomplete : Error<
3708+
"cannot expand expression of incomplete type %0">;
37053709
def err_expansion_stmt_lambda : Error<
37063710
"cannot expand lambda closure type">;
37073711

clang/lib/Sema/SemaExpand.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ StmtResult Sema::BuildNonEnumeratingCXXExpansionStmtPattern(
287287
RParenLoc);
288288
}
289289

290+
if (RequireCompleteType(ExpansionInitializer->getExprLoc(),
291+
ExpansionInitializer->getType(),
292+
diag::err_expansion_stmt_incomplete))
293+
return StmtError();
294+
295+
if (ExpansionInitializer->getType()->isVariableArrayType()) {
296+
Diag(ExpansionInitializer->getExprLoc(), diag::err_expansion_stmt_vla)
297+
<< ExpansionInitializer->getType();
298+
return StmtError();
299+
}
300+
290301
// Otherwise, if it can be an iterating expansion statement, it is one.
291302
DeclRefExpr *Index = BuildIndexDRE(*this, ESD);
292303
IterableExpansionStmtData Data = TryBuildIterableExpansionStmtInitializer(

0 commit comments

Comments
 (0)