incorrect results for g++ -std=c++11 -O3 -DNDEBUG
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gcc-defaults (Ubuntu) |
Invalid
|
Undecided
|
Unassigned |
Bug Description
This bug report is a simplification of the following issue reported against CppAD:
https:/
The attached file (to_string.sh) is a bash script that demonstrates the problem.
In summary (of running to_string.sh) the following source code has a different result for ok
depending on if PRINT_BEFOR_CHECK is 0 or 1.
int max = std::numeric_
os << max;
std::string s = os.str();
int check = string2int(s);
# if PRINT_BEFORE_CHECK
std::cout << "max = " << max << ", check = " << check << "\n";
# endif
ok &= max == check;
ProblemType: Bug
DistroRelease: Ubuntu 18.04
Package: g++ 4:7.4.0-1ubuntu2.2
ProcVersionSign
Uname: Linux 4.15.0-51-generic x86_64
ApportVersion: 2.20.9-0ubuntu7.6
Architecture: amd64
CurrentDesktop: ubuntu:GNOME
Date: Sun Jun 9 07:58:29 2019
InstallationDate: Installed on 2018-10-24 (227 days ago)
InstallationMedia: Ubuntu 18.04.1 LTS "Bionic Beaver" - Release amd64 (20180725)
SourcePackage: gcc-defaults
UpgradeStatus: No upgrade log present (probably fresh install)
Changed in gcc-defaults (Ubuntu): | |
status: | New → Invalid |
I think this is a gcc problem because it reproduces on Fedora 33 with
g++ (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)
In addition, the only compiler flag that is necessary to demonstrate the bug is '-O3' (on my Fedora 33 system). Any other level of optimization passes the test.