cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[BUG] Parsing bug when multiplying a negative number

Open mike919192 opened this issue 1 year ago • 7 comments
trafficstars

Describe the bug Multiplying by a negative number is being parsed incorrectly. Putting the negative number in parenthesis is a workaround to parse it correctly.

To Reproduce This cpp2 code:

#include <iostream>
#include <string>

main: () = {
    
    std::cout << 1 * -1 << name() << "\n";
    std::cout << 1 * (-1) << name() << "\n";
}

Compiles to this cpp code


//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"



//=== Cpp2 type definitions and function declarations ===========================

#include <iostream>
#include <string>

auto main() -> int;

//=== Cpp2 function definitions =================================================


auto main() -> int{

    std::cout << *cpp2::impl::assert_not_null(1) - 1 << name() << "\n";
    std::cout << 1 * (-1) << name() << "\n";
}

https://godbolt.org/z/KMc6sxoPe

Additional context This is present in the head, but not in the release 0.7.0

mike919192 avatar May 12 '24 22:05 mike919192