diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2023-09-16 22:38:47 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2023-09-17 12:41:11 +0100 |
| commit | 0fa8cf44f69dcb00dacf180d88ebfa09bc462120 (patch) | |
| tree | 99b05b6dad404a5008677de5b056adec44db24f2 /test | |
| parent | 28caaea0938e938de96cc66a49f670005a2df9d4 (diff) | |
| download | zig-0fa8cf44f69dcb00dacf180d88ebfa09bc462120.tar.gz zig-0fa8cf44f69dcb00dacf180d88ebfa09bc462120.zip | |
translate-c: do not translate macros which use arguments as struct/union/enum names
Consider this C macro:
```c
#define FOO(x) struct x
```
Previously, translate-c did not detect that the `x` in the body referred
to the argument, so wrongly translated this code as using the
nonexistent `struct_x`. Since undefined identifiers are noticed in
AstGen, this prevents the translated file from being usable at all.
translate-c now instead detects this case and emits an appropriate
compile error in the macro's place.
Diffstat (limited to 'test')
| -rw-r--r-- | test/translate_c.zig | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/test/translate_c.zig b/test/translate_c.zig index 3a453b9aa8..3fad7f8fe5 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -4129,4 +4129,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ }) != 0) {} \\} }); + + cases.add("macro using argument as struct name is not translated", + \\#define FOO(x) struct x + , &[_][]const u8{ + \\pub const FOO = @compileError("unable to translate macro: untranslatable usage of arg `x`"); + }); } |
