Skip to content

Commit

Permalink
[cpp] const pointers can no longer be implciitly converted to non-const
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed May 24, 2024
1 parent 2aaebab commit fb301d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cpp/src/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ namespace build
ast::variable_declaration
{
.var_name = "outname",
.type_name = "i8&",
.type_name = "i8& const",
.initialiser = ast::expression{.expr = ast::null_literal{}}
},
},
Expand All @@ -250,7 +250,7 @@ namespace build
ast::variable_declaration
{
.var_name = "filename",
.type_name = "i8&",
.type_name = "i8& const",
.initialiser = ast::expression{.expr = ast::null_literal{}}
},
},
Expand All @@ -268,7 +268,7 @@ namespace build
ast::variable_declaration
{
.var_name = "filename",
.type_name = "i8&",
.type_name = "i8& const",
.initialiser = ast::expression{.expr = ast::null_literal{}}
},
},
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ conversion_type type::is_implicitly_convertible_to(const type& rhs) const
{
if(this->without_qualifiers() == rhs.without_qualifiers())
{
if(this->is_pointer() && this->is_const() && !rhs.is_const())
{
return conversion_type::impossible;
}
return conversion_type::none;
}
if(this->is_weak() || rhs.is_weak())
Expand Down
4 changes: 3 additions & 1 deletion samples/scratchpad.psy
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ print_digit :: (digit : i64 weak) -> u0

is_odd :: (val : i64) -> bool
{
mystr : i8& const := "well met";

half : i64 := (val / 2);
low_half : i64 := ((val - 1) / 2);
return (half == low_half);
Expand Down Expand Up @@ -37,7 +39,7 @@ get_fox :: () -> animal
return ret;
}

puts :: (str : i8&) -> u0 := extern;
puts :: (str : i8& const) -> u0 := extern;
print_hello :: () -> u0
{
buffer : i8& := __builtin_malloc(6 * (sizeof i8));
Expand Down

0 comments on commit fb301d6

Please sign in to comment.