-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
boost::container::flat_map force_copy violates strict-aliasing rule #252
Comments
I bumped into a version of this problem that's reproducible on GCC trunk #include <utility>
#include <boost/container/flat_map.hpp>
namespace bc = boost::container;
int main() {
bc::flat_map<int, int> map {
std::pair(0, 1),
std::pair(1, 2),
std::pair(2, 4)
};
if (map.size() != 3) {
return 1;
}
int i = 0;
for (const auto &[k, v] : map) {
++i;
}
if (i != 3) {
return 2;
}
return 0;
} When this is compiled with Here's a Compiler Explorer link showing the result: https://godbolt.org/z/7W5eGrKGE |
Note that we have to crank the subslot for this. I've added a fudge .1 which we should drop on 1.86.0. Closes: https://bugs.gentoo.org/933289 Bug: freeorion/freeorion#4949 Bug: boostorg/container#252 Bug: boostorg/container#281 Bug: https://bugs.gentoo.org/932780 Bug: https://bugs.gentoo.org/931587 Signed-off-by: Sam James <sam@gentoo.org>
Thanks for the report. The strict aliasing violation was needed only for ancient compilers so the following commit removes it for C++11 o newer: |
Hi everyone!
g++ v13.1.0, v13.2.0, boost v1.82, MSYS2 MINGW64_NT-10.0-19044.
Discussion links:
msys2/MINGW-packages#17977
msys2/MINGW-packages#17977 (comment)
The following example has different behavior depending on compiler optimization flags:
Expected behavior
Without optimization flags (-O0, -O1) everything fine.
g++ -O0 -o boost_v1.82_flat_map_it_bug boost_v1.82_flat_map_it_bug.cpp
Actual behavior
With optimization flags (-O2, -O3) iterator has bad value.
g++ -O2 -o boost_v1.82_flat_map_it_bug boost_v1.82_flat_map_it_bug.cpp
The issue does not happen in Linux with gcc 13.2.1 toolchain.
The text was updated successfully, but these errors were encountered: