Open Yeaseen opened 6 days ago
I found post-decrement is also problematic, making it a general flaw.
#include<stdio.h>
struct s {
int i;
};
int f(void) {
struct s *p;
int j = 42;
p = &((struct s){j--}); // Compound literal with address-of operator
return p->i;
}
int main() {
int result = f();
printf("Result of f: %d\n", result);
return 0;
}
Same error.
Description
The
c2rust
tool fails to translate valid C code that uses the post-increment operator (j++
) inside a compound literal. This occurs even though the code is valid and compiles successfully with standard C compilers like GCC or Clang.If a simple integer (e.g.,
42
) is used instead ofj++
,c2rust
handles the compound literal without any issues.Source C code
Actual Behavior
c2rust
fails to translate the function f and gives the following error:Expected Behavior
c2rust
should translate the compound literal with j++ into equivalent Rust code.Observation
Interestingly,
c2rust
can translate the following C code perfectly, and the translated rust code prints42