Skip to content

Evaluation order in struct expressions can be incorrect #4445

@powerboat9

Description

@powerboat9

Summary

https://doc.rust-lang.org/reference/expressions.html#r-expr.operand-order

GCCRS appears to evaluate child expressions of struct expressions in field definition order, not left to right inside the expression.

Reproducer

#![no_core]

extern "C" {
    fn first_call() -> i32;
    fn second_call() -> i32;
}

pub fn get_0() -> i32 {
    struct S {
        a: i32,
        b: i32
    };

    let x = unsafe {
        S { b: first_call (), a: second_call () }
    };

    x.a
}

Does the code make use of any (1.49) nightly feature ?

  • Nightly

Godbolt link

https://godbolt.org/z/9hEoM8YGd

Actual behavior

second_call is called first

Expected behavior

first_call is called first

GCC Version

308bc94

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