Skip to content

Commit 61da5e6

Browse files
committed
Improve type checking of integer literals
Signed-off-by: Roberto Raggi <roberto.raggi@gmail.com>
1 parent c64b3f6 commit 61da5e6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/parser/cxx/parser.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <cstring>
4444
#include <format>
4545
#include <iostream>
46+
#include <limits>
4647
#include <ranges>
4748
#include <unordered_set>
4849

@@ -483,8 +484,12 @@ auto Parser::parse_literal(ExpressionAST*& yyast) -> bool {
483484
ast->type = control_->getLongIntType();
484485
else if (components.isUnsigned)
485486
ast->type = control_->getUnsignedIntType();
486-
else
487-
ast->type = control_->getIntType();
487+
else {
488+
if (ast->literal->integerValue() > std::numeric_limits<int>::max())
489+
ast->type = control_->getLongIntType();
490+
else
491+
ast->type = control_->getIntType();
492+
}
488493

489494
return true;
490495
}

0 commit comments

Comments
 (0)