You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run the following code with any build mode but debug mode.
Sample stoi.cpp:
#include<iostream>intmain() {
try {
// Can be stoi, stoul, stoull, etc.std::stoi("test", nullptr, 0);
} catch (...) {
}
// Commenting out this line fixes the runtime error.// Only causes an error on Fast/Small if it's equal to the function above.std::stoi("0");
return0;
}
Sample stoi_safe.cpp:
#include<iostream>intmain() {
try {
// Can be stoi, stoul, stoull, etc.std::stoi("test", nullptr, 0);
} catch (...) {
}
// Commenting out this line fixes the runtime error.// Only causes an error on Fast/Small if it's equal to the function above.std::stoll("0");
return0;
}
Expected Behavior
The code should run (and essentially do nothing) successfully.
$ zig run -lc++ -O Debug stoi_safe.cpp
$ zig run -lc++ -O Debug stoi.cpp
My attempt at replicating the flags passed to Clang by looking at the outputs of --verbose-cc of -O ReleaseSmall:
$ zig run -lc++ -O ReleaseSafe stoi_safe.cpplibc++abi: terminating with uncaught exception of type std::invalid_argument: stoi: no conversionAborted (core dumped)
$ zig run -lc++ -O ReleaseSafe stoi.cpplibc++abi: terminating with uncaught exception of type std::invalid_argument: stoi: no conversionAborted (core dumped)
Fast/Small:
$ zig run -lc++ -O ReleaseSmall stoi_safe.cpp
$ zig run -lc++ -O ReleaseSmall stoi.cpplibc++abi: terminating with uncaught exception of type std::invalid_argument: stoi: no conversionAborted (core dumped)
The text was updated successfully, but these errors were encountered:
sagehane
added
the
bug
Observed behavior contradicts documented or intended behavior
label
Feb 14, 2022
sagehane
changed the title
C++: std::stoi causes issues only on non-debug builds
C++: wrong exception handling with std::stoi on non-debug builds
Feb 15, 2022
Update. I tried running the same code with 0.10.0-dev.2836+2360f8c49 and it seems to throw that uncaught exception error on safe mode even after commenting out the 2nd call to stoi. The behavior doesn't seem to have changed for other release modes.
Zig Version
0.10.0-dev.717+90f2a8d9c
Steps to Reproduce
Reproduced on NixOS Unstable and Arch Linux.
Run the following code with any build mode but debug mode.
Sample
stoi.cpp
:Sample
stoi_safe.cpp
:Expected Behavior
The code should run (and essentially do nothing) successfully.
My attempt at replicating the flags passed to Clang by looking at the outputs of
--verbose-cc
of-O ReleaseSmall
:Actual Behavior
Causes a runtime error.
Safe:
Fast/Small:
The text was updated successfully, but these errors were encountered: