mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Formatting option "%h" now supports pointers.
This commit is contained in:
@@ -495,6 +495,11 @@ fn usz? Formatter.vprintf(&self, String format, any[] anys)
|
||||
out = ((char*)current.ptr)[:current.type.sizeof];
|
||||
break;
|
||||
}
|
||||
if (current.type.kindof == POINTER)
|
||||
{
|
||||
out = ((*(char**)current.ptr))[:current.type.inner.sizeof];
|
||||
break;
|
||||
}
|
||||
total_len += self.out_substr("<INVALID>")!;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
- Catch accidental `foo == BAR;` where `foo = BAR;` was most likely intended. #2274
|
||||
- Improve error message when doing a rethrow in a function that doesn't return an optional.
|
||||
- Add `--list-asm` to view all supported `asm` instructions.
|
||||
- Formatting option "%h" now supports pointers.
|
||||
|
||||
### Fixes
|
||||
- mkdir/rmdir would not work properly with substring paths on non-windows platforms.
|
||||
|
||||
@@ -3241,9 +3241,10 @@ static inline Type *type_flatten_no_export(Type *type)
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool type_flat_is_char_array_slice(Type *type)
|
||||
static inline bool type_flat_is_valid_for_arg_h(Type *type)
|
||||
{
|
||||
type = type_flatten(type);
|
||||
if (type->type_kind == TYPE_POINTER) return true;
|
||||
if (type->type_kind != TYPE_ARRAY && type->type_kind != TYPE_SLICE) return false;
|
||||
switch (type->array.base->type_kind)
|
||||
{
|
||||
|
||||
@@ -2168,9 +2168,9 @@ NEXT_FLAG:
|
||||
goto NEXT;
|
||||
case 'H':
|
||||
case 'h':
|
||||
if (!type_flat_is_char_array_slice(type))
|
||||
if (!type_flat_is_valid_for_arg_h(type))
|
||||
{
|
||||
RETURN_SEMA_ERROR(vaargs[idx], "Expected a char array or slice here.");
|
||||
RETURN_SEMA_ERROR(vaargs[idx], "Expected a pointer, char array or slice here.");
|
||||
}
|
||||
goto NEXT;
|
||||
default:
|
||||
|
||||
13
test/test_suite/attributes/format_h.c3t
Normal file
13
test/test_suite/attributes/format_h.c3t
Normal file
@@ -0,0 +1,13 @@
|
||||
module test;
|
||||
import std;
|
||||
|
||||
struct Foo
|
||||
{
|
||||
int x, y;
|
||||
}
|
||||
fn int main()
|
||||
{
|
||||
Foo f = { 33, 12323 };
|
||||
io::printfn("%h", &f);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user