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 f95c18d8f1f99dc15a070b93b93c30e7b222202c..5b217473241ff9b1bb2b186181bf30aa36626725 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 fb8e54d5e67efd4422a3cfd539aa9ff31c7a341f..89c6bda6327cf2bd1e908e142e189ae46a999d19 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`"); + }); } -- 2.54.0