diff --git a/src/translate_c.zig b/src/translate_c.zig index 5b217473241ff9b1bb2b186181bf30aa36626725..ccc109906423480b62d1cf3b990f167043366d80 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -401,7 +401,7 @@ pub fn translate( .name = decl.name, .init = try Tag.import_builtin.create(context.arena, decl.name), }); - try context.global_scope.nodes.append(builtin); + try addTopLevelDecl(&context, decl.name, builtin); } } @@ -5347,7 +5347,10 @@ fn transPreprocessorEntities(c: *Context, unit: *clang.ASTUnit) Error!void { }, .Nl, .Eof => { // this means it is a macro without a value - // we don't care about such things + // We define it as an empty string so that it can still be used with ++ + const str_node = try Tag.string_literal.create(c.arena, "\"\""); + const var_decl = try Tag.pub_var_simple.create(c.arena, .{ .name = name, .init = str_node }); + try c.global_scope.macro_table.put(name, var_decl); continue; }, .LParen => { diff --git a/test/translate_c.zig b/test/translate_c.zig index 89c6bda6327cf2bd1e908e142e189ae46a999d19..5ff6c22ead59dcb1c488fd44a5c32c0c2a6c2f81 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -3678,4 +3678,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub const FOO = @compileError("unable to translate macro: undefined identifier `std`"); }); + + cases.add("Macro without a value", + \\#define FOO + , &[_][]const u8{ + \\pub const FOO = ""; + }); }