Skip to content

Segmentation Fault when compiling std.mem.swap of anonymous tuple #20746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bartbaer opened this issue Jul 22, 2024 · 1 comment
Closed

Segmentation Fault when compiling std.mem.swap of anonymous tuple #20746

bartbaer opened this issue Jul 22, 2024 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@bartbaer
Copy link

Zig Version

0.14.0-dev.208+854e86c56

Steps to Reproduce and Observed Behavior

When I tried to swap two anonymous tuples, the build failed. (on linux x86_64)

const std = @import("std");
pub fn main() void {
    var a = [_]struct{i32, i32}{.{1, 2}, .{3, 4}};
    std.mem.swap(struct{i32, i32}, &a[0], &a[1]);
}

Trying to compile it, you get:

$ cat main.zig
const std = @import("std");
pub fn main() void {
    var a = [_]struct{i32, i32}{.{1, 2}, .{3, 4}};
    std.mem.swap(struct{i32, i32}, &a[0], &a[1]);
}
$ zig build-exe main.zig
Segmentation fault

However, if I give the tuple a name, it works.
This compiles fine:

const std = @import("std");
const Pair = struct{i32, i32};
pub fn main() void {
    var a = [_]Pair{.{1, 2}, .{3, 4}};
    std.mem.swap(Pair, &a[0], &a[1]);
}

I tried looking for issues with segfault and swap, but did not find anything.

Expected Behavior

The compiler should not segfault, it should output a program or an error.

@bartbaer bartbaer added the bug Observed behavior contradicts documented or intended behavior label Jul 22, 2024
@Vexu
Copy link
Member

Vexu commented Jul 22, 2024

Duplicate of #19497

@Vexu Vexu marked this as a duplicate of #19497 Jul 22, 2024
@Vexu Vexu closed this as not planned Won't fix, can't repro, duplicate, stale Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants