Skip to content

Commit 8636d9a

Browse files
committed
Assert failed when parsing enumerator in debug mode
Fixes #597 Signed-off-by: Roberto Raggi <roberto.raggi@gmail.com>
1 parent 6deb75c commit 8636d9a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/parser/cxx/parser.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6621,23 +6621,31 @@ void Parser::parse_enumerator_list(List<EnumeratorAST*>*& yyast,
66216621
parse_enumerator(enumerator, type);
66226622

66236623
if (!enumerator->expression) {
6624+
// no explicit value given, so we need to increment the last value
6625+
66246626
if (lastValue.has_value()) {
6627+
// we have a last value, so we can increment it
66256628
if (control_->is_unsigned(type)) {
6629+
// increment the last value as unsigned
66266630
if (auto v = interp.toUInt(lastValue.value())) {
66276631
lastValue = v.value() + 1;
66286632
} else {
66296633
lastValue = std::nullopt;
66306634
}
66316635
} else {
6636+
// increment the last value as signed
66326637
if (auto v = interp.toInt(lastValue.value())) {
66336638
lastValue = v.value() + 1;
66346639
} else {
66356640
lastValue = std::nullopt;
66366641
}
66376642
}
6643+
6644+
// set the value of the enumerator symbol
6645+
enumerator->symbol->setValue(*lastValue);
66386646
}
6639-
enumerator->symbol->setValue(*lastValue);
66406647
} else {
6648+
// refresh the last value from the enumerator expression
66416649
lastValue = enumerator->symbol->value();
66426650
}
66436651

0 commit comments

Comments
 (0)