Skip to content

Commit c7fe1fb

Browse files
committed
Improve integral conversions
1 parent 462428d commit c7fe1fb

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/parser/cxx/parser.cc

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,19 +2546,11 @@ auto Parser::check_member_access(MemberExpressionAST* ast) -> bool {
25462546
field && !field->isStatic()) {
25472547
auto cv2 = strip_cv(ast->type);
25482548

2549-
auto vq = is_volatile(cv1) || is_volatile(cv2);
2550-
auto cq = is_const(cv1) || is_const(cv2);
2549+
if (is_volatile(cv1) || is_volatile(cv2))
2550+
ast->type = control_->add_volatile(ast->type);
25512551

2552-
CvQualifiers cv = CvQualifiers::kNone;
2553-
if (vq) cv = CvQualifiers::kVolatile;
2554-
2555-
if (!field->isMutable() && cq) {
2556-
cv = merge_cv(cv, CvQualifiers::kConst);
2557-
}
2558-
2559-
if (cv != CvQualifiers::kNone) {
2560-
ast->type = control_->getQualType(ast->type, cv);
2561-
}
2552+
if (!field->isMutable() && (is_const(cv1) || is_const(cv2)))
2553+
ast->type = control_->add_const(ast->type);
25622554
}
25632555
}
25642556
}
@@ -2766,6 +2758,7 @@ auto Parser::check_static_cast(CppCastExpressionAST* ast) -> bool {
27662758

27672759
const auto cv1 = get_cv_qualifiers(ast->expression->type);
27682760
const auto cv2 = get_cv_qualifiers(targetType);
2761+
27692762
if (!check_cv_qualifiers(cv2, cv1)) return false;
27702763

27712764
if (implicit_conversion(ast->expression, ast->type)) return true;
@@ -2812,10 +2805,10 @@ auto Parser::check_cast_to_derived(const Type* targetType,
28122805
}
28132806

28142807
auto Parser::get_cv_qualifiers(const Type* type) const -> CvQualifiers {
2815-
if (auto qualType = type_cast<QualType>(type)) {
2816-
return qualType->cvQualifiers();
2817-
}
2818-
return CvQualifiers::kNone;
2808+
CvQualifiers cv = CvQualifiers::kNone;
2809+
if (control_->is_const(type)) cv = merge_cv(cv, CvQualifiers::kConst);
2810+
if (control_->is_volatile(type)) cv = merge_cv(cv, CvQualifiers::kVolatile);
2811+
return cv;
28192812
}
28202813

28212814
auto Parser::parse_builtin_bit_cast_expression(ExpressionAST*& yyast,
@@ -6815,6 +6808,8 @@ auto Parser::implicit_conversion(ExpressionAST*& expr,
68156808
if (!expr || !expr->type) return false;
68166809
if (!destinationType) return false;
68176810

6811+
if (control_->is_same(expr->type, destinationType)) return true;
6812+
68186813
auto savedExpr = expr;
68196814
auto didConvert = false;
68206815

@@ -6826,6 +6821,10 @@ auto Parser::implicit_conversion(ExpressionAST*& expr,
68266821
didConvert = true;
68276822
}
68286823

6824+
if (control_->is_scalar(expr->type)) {
6825+
expr->type = control_->remove_cv(expr->type);
6826+
}
6827+
68296828
if (integral_promotion(expr)) return true;
68306829
if (floating_point_promotion(expr)) return true;
68316830
if (integral_conversion(expr, destinationType)) return true;
@@ -7905,6 +7904,11 @@ auto Parser::parse_brace_or_equal_initializer(ExpressionAST*& yyast) -> bool {
79057904
parse_error("expected an intializer");
79067905
}
79077906

7907+
if (ast->expression) {
7908+
ast->type = ast->expression->type;
7909+
ast->valueCategory = ast->expression->valueCategory;
7910+
}
7911+
79087912
return true;
79097913
}
79107914

0 commit comments

Comments
 (0)