Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/parser/cxx/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5368,6 +5368,28 @@ auto Parser::parse_init_declarator(InitDeclaratorAST*& yyast,

if (auto var = symbol_cast<VariableSymbol>(ast->symbol)) {
var->setInitializer(initializer);

if (auto ty = type_cast<UnboundedArrayType>(ast->symbol->type())) {
BracedInitListAST* bracedInitList = nullptr;

if (auto init = ast_cast<BracedInitListAST>(ast->initializer)) {
bracedInitList = init;
} else if (auto init = ast_cast<EqualInitializerAST>(ast->initializer)) {
bracedInitList = ast_cast<BracedInitListAST>(init->expression);
}

if (bracedInitList) {
const auto count =
std::ranges::distance(ListView{bracedInitList->expressionList});

if (count > 0) {
const auto arrayType =
control()->getBoundedArrayType(ty->elementType(), count);

symbol->setType(arrayType);
}
}
}
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/ast/for_range_statement_02.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int main() {
// CHECK-NEXT: identifier: key
// CHECK-NEXT: name-id
// CHECK-NEXT: identifier: value
// CHECK-NEXT: range-initializer: id-expression [lvalue int [][2]]
// CHECK-NEXT: range-initializer: id-expression [lvalue int [1][2]]
// CHECK-NEXT: unqualified-id: name-id
// CHECK-NEXT: identifier: map
// CHECK-NEXT: statement: compound-statement
6 changes: 6 additions & 0 deletions tests/unit_tests/sema/sizeof_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ static_assert(sizeof(long) == 4);
static_assert(sizeof(unsigned long) == 4);
static_assert(sizeof(long double) == 16);
#endif

int elements[] = {1, 2, 3, 4, 5};
static_assert(sizeof(elements) == 5 * sizeof(int));

double d[]{1.0, 2.0, 3.0};
static_assert(sizeof(d) == 3 * sizeof(double));