Skip to content

Unexpected result when assigning a vector to itself #6659

@jedisct1

Description

@jedisct1
const std = @import("std");
const Vector = std.meta.Vector;

pub fn main() anyerror!void {
    var b = Vector(4, u32){ 1, 2, 3, 4 };
    b = Vector(4, u32){ b[3], b[2], b[1], b[0] };
    std.debug.print("{}\n", .{b});
}

Prints

{ 4, 3, 3, 4 }

instead of

{ 4, 3, 2, 1 }

Using a temporary variable produces the correct output. Is assigning a vector containing some of its own elements UB?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions