From f5553bfefcca2690b557ea080d8ae431b7d9b5d9 Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Tue, 31 Aug 2021 13:33:44 -0700 Subject: [PATCH] translate-c: Only consider public decls in isBuiltinDefined --- src/translate_c.zig | 1 + test/translate_c.zig | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/translate_c.zig b/src/translate_c.zig index f95c18d8f1..5b21747324 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -1990,6 +1990,7 @@ fn transImplicitCastExpr( fn isBuiltinDefined(name: []const u8) bool { inline for (meta.declarations(std.zig.c_builtins)) |decl| { + if (!decl.is_pub) continue; if (std.mem.eql(u8, name, decl.name)) return true; } return false; diff --git a/test/translate_c.zig b/test/translate_c.zig index fb8e54d5e6..89c6bda632 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -3672,4 +3672,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub const FOO = __builtin_popcount; }); + + cases.add("Only consider public decls in `isBuiltinDefined`", + \\#define FOO std + , &[_][]const u8{ + \\pub const FOO = @compileError("unable to translate macro: undefined identifier `std`"); + }); }