Commit 39f43fea8d
Changed files (2)
test
src/translate_c.zig
@@ -5647,7 +5647,7 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node {
switch (m.list[m.i].id) {
.IntegerLiteral => |suffix| {
var radix: []const u8 = "decimal";
- if (lit_bytes.len > 2 and lit_bytes[0] == '0') {
+ if (lit_bytes.len >= 2 and lit_bytes[0] == '0') {
switch (lit_bytes[1]) {
'0'...'7' => {
// Octal
test/translate_c.zig
@@ -3842,4 +3842,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
, &[_][]const u8{
\\pub const FOO = "";
});
+
+ cases.add("leading zeroes",
+ \\#define O_RDONLY 00
+ \\#define HELLO 000
+ \\#define ZERO 0
+ \\#define WORLD 00000123
+ , &[_][]const u8{
+ \\pub const O_RDONLY = @as(c_int, 0o0);
+ \\pub const HELLO = @as(c_int, 0o00);
+ \\pub const ZERO = @as(c_int, 0);
+ \\pub const WORLD = @as(c_int, 0o0000123);
+ });
}