aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-03-19 20:34:06 +0000
committergingerBill <bill@gingerbill.org>2019-03-19 20:34:06 +0000
commit0e1cfa5a0aa9b68a34a15a6f293f729d66e0ade4 (patch)
treedfd4556f55d81318ea964591f4dfaac074580381 /src/check_expr.cpp
parent400558abcd865f5b9ad4da2975b63eadacb9dff3 (diff)
Disallow casting to and from cstring/pointers
TODO: get a better error message
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index d0e18d89f..c5cc82e1c 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -1418,6 +1418,9 @@ bool check_representable_as_constant(CheckerContext *c, ExactValue in_value, Typ
return false;
// return true;
}
+ if (in_value.kind == ExactValue_String) {
+ return false;
+ }
if (out_value) *out_value = in_value;
} else if (is_type_bit_set(type)) {
if (in_value.kind == ExactValue_Integer) {
@@ -1882,6 +1885,8 @@ bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) {
return true;
}
+ bool is_constant = operand->mode == Addressing_Constant;
+
Type *x = operand->type;
Type *src = core_type(x);
Type *dst = core_type(y);
@@ -1964,20 +1969,20 @@ bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) {
}
// cstring -> ^u8
if (are_types_identical(src, t_cstring) && is_type_u8_ptr(dst)) {
- return true;
+ return !is_constant;
}
// cstring -> rawptr
if (are_types_identical(src, t_cstring) && is_type_rawptr(dst)) {
- return true;
+ return !is_constant;
}
// ^u8 -> cstring
if (is_type_u8_ptr(src) && are_types_identical(dst, t_cstring)) {
- return true;
+ return !is_constant;
}
// rawptr -> cstring
if (is_type_rawptr(src) && are_types_identical(dst, t_cstring)) {
- return true;
+ return !is_constant;
}
// proc <-> proc
if (is_type_proc(src) && is_type_proc(dst)) {