c3lang / c3c

Compiler for the C3 language
GNU Lesser General Public License v3.0
1.35k stars 80 forks source link

`$typeof(*x)` should be valid when x is an `[out]` parameter #1226

Closed cbuttner closed 2 days ago

cbuttner commented 3 days ago

We run into this problem here:

/**
 * @param [out] x "The variable or dereferenced pointer to store to."
 * @param value "The value to store."
 * @param $alignment "The alignment to assume for the store"
 * @return "The value of x"
 *
 * @require $assignable(value, $typeof(*x)) : "The value doesn't match the variable"
                                       ^^
Error: 'out' parameters may not be read.
 * @require @constant_is_power_of_2($alignment) : "The alignment must be a power of two"
 **/
macro @unaligned_store(&x, value, usz $alignment) @builtin
{
    return $$unaligned_store(x, ($typeof(*x))value, $alignment);
}
lerno commented 3 days ago

Some overeager evaluation there. Please try now.

cbuttner commented 2 days ago

👍