0.16.0 C translation issue

I was moving one of my projects to 0.16.0 and I think I found a c translation issue. I created a minimal example here. The main branch is Zig 0.15 and compiles and runs successfully. On the 0.16 branch I encountered this error:

 .zig-cache/o/f1d5d3f7cb20e63e6227e524f5c0c539/libnotify.zig:6617:194: error: expected ';' after statement
        if (__builtin.constant_p(!(@as(c_int, 0) != 0)) != 0) if (!(@as(c_int, 0) != 0)) _ = g_string_free(string, @intFromBool(!(@as(c_int, 0) != 0))) else _ = g_string_free_and_steal(string) else _ = g_string_free(string, @intFromBool(!(@as(c_int, 0) != 0)));

This is the full translated function:

pub fn g_autoptr_cleanup_gstring_free(arg_string: [*c]GString) callconv(.c) void {
    var string = arg_string;
    _ = &string;
    if (string != null) {
        if (__builtin.constant_p(!(@as(c_int, 0) != 0)) != 0) if (!(@as(c_int, 0) != 0)) _ = g_string_free(string, @intFromBool(!(@as(c_int, 0) != 0))) else _ = g_string_free_and_steal(string) else _ = g_string_free(string, @intFromBool(!(@as(c_int, 0) != 0)));
    }
}

It seems in 0.16.0 invalid Zig is being generated from glib. I also had to add #define _Pragma(x) to my c header file in Zig 0.16.0 to get it to compile libnotify. Does anyone have any idea if this is a bug or if I am incorrectly porting this to 0.16.0?

The constant_p builtin is mentioned in this recent issue: https://codeberg.org/ziglang/translate-c/issues/322. If not the same issue, I’m sure your error and usecase is welcome information in that repo.

2 Likes