cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[BUG] incorrect parse of negative number in for-range

Open ishani opened this issue 2 months ago • 0 comments

Providing a negative number as the start of a for-range produces broken cpp1 code: the - negative is parsed to apply to the resulting range object rather than the number itself. To make it work one must surround the value with parentheses to clarify possession.

To Reproduce https://godbolt.org/z/bMafrYvEM

main: () -> int = {
    
    // BROKEN - will not compile
    // produces   -cpp2::range(2,2)   rather than   cpp2::range(-2,2) 
    for -2 ..< 2 do (y) {
        ...
    }

    // WORKAROUND - produces cpp2::range((-2),2) 
    for (-2) ..< 2 do (z) {
        ...
    }

    // NB end value is parsed correctly
    for (-5) ..< -2 do (x) {
        ...
    }
}

ishani avatar Oct 22 '25 19:10 ishani