immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
3.79k stars 219 forks source link

Switch case with ranges #1055

Open sparkforreg opened 6 months ago

sparkforreg commented 6 months ago

Is it a bug that case with a range is not translated correctly?

here is a c code example

switch(5) { case 3 … 7 : print(“1”); default: print(“2”); }

fw-immunant commented 5 months ago

This isn't a bug per se, but a reasonable enhancement request--we don't yet support this nonstandard extension to C.

I hadn't realized this extension existed, but it seems widely supported (by GCC, Clang, and Sun's compilers at least) so it might be worth handling. Doing so would involve checking caseStmtIsGNURange when processing the Clang AST and probably rejiggering our CStmtKind enum a bit to be able to carry the information needed for range case statements.

sparkforreg commented 5 months ago

thanks for checking