Open tau-dev opened 2 weeks ago
Can you please specify the exact compiler, which causes such behavior (I mean version, optimization flags, etc...)? What numbers are you printing? Are they of primitive data types, or something else?
I tried compiling main.cpp with g++ -O1
on Linux and clang++ -O1
on Linux and Windows. You probably only tested MSVC, which does not exploit UB nearly as much.
Yes, I tried that only on MSVC. I will try also gcc soon. Are there some specific numbers, printing of which fails... or your issue applies to the general case?
Just trying to run main.cpp without modifications
The code contains undefined behavior, such as integer overflows: https://github.com/tigranh/lr_printer/blob/a85bfbc218d410d0cbfb4be14fb3fd10cfd27bc7/lr_printer.hpp#L180 https://github.com/tigranh/lr_printer/blob/a85bfbc218d410d0cbfb4be14fb3fd10cfd27bc7/lr_printer_2_digits.hpp#L231
as well as pointer-out-of bounds on https://github.com/tigranh/lr_printer/blob/a85bfbc218d410d0cbfb4be14fb3fd10cfd27bc7/lr_printer_2_digits.hpp#L111 (even having a pointer out-of-bound of an array is UB, you do not need to dereference it).
Because of this, the code crashes at any degree of optimization in Clang and GCC. Performance measurements of non-optimized builds are near meaningless.