cppfront
cppfront copied to clipboard
[BUG] z: u8 = x + y; does not compile
trafficstars
The following code does not compile.
main.cpp2
main: () = {
x: u8 = 1;
y: u8 = 2;
z: u8 = x + y;
std::cout << z << std::endl;
}
main.cpp1 generated
auto main() -> int{
cpp2::u8 x {1};
cpp2::u8 y {2};
cpp2::u8 z {cpp2::move(x) + cpp2::move(y)};
std::cout << cpp2::move(z) << std::endl;
}
Compiler error
main.cpp2: In function 'int main()':
main.cpp2:4:31: error: narrowing conversion of '(((int)cpp2::move<unsigned char&>(x)) + ((int)cpp2::move<unsigned char&>(y)))' from 'int' to 'cpp2::u8' {aka 'unsigned char'} [-Wnarrowing]
Example https://cpp2.godbolt.org/z/r6r9d8KMP