Gcc std :: regex with errors -fpack-struct seg

Consider the following simple C ++ program

#include <iostream> #include <regex> int main(int argc, char * argv[]) { std::regex foobar( "[A]+"); return 0; } 

When compiling with -fpack-struct = 1, these are seg faults

 g++-5 -std=gnu++14 ./fpack_regex.cpp -fpack-struct=1 -o a.out && a.out Segmentation fault (core dumped) 

Until

 g++-5 -std=gnu++14 ./fpack_regex.cpp -o a.out && a.out 

works great.

Any hint why the pack-struct = 1 parameter might cause this failure?

+5
source share
1 answer

The -fpack-struct switch can be very dangerous, for example. see gcc warning about it:

The main problem that I see is that your code is not binary compatible with the standard library (usually it is not compiled with structured packages), so calls (with passing structures) to it may fail (as they do on actually).

It is recommended that you do not package all structures with this switch, but if you need a packaging structure, pack only the ones you need. I also read that recompiling libstd and / or libs that you use with the same fpack-struct may help, but this is a risky option.

Some information is also here (old gcc bug regarding fpack-struct), it is deprecated, but may be useful: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14173

+2
source

Source: https://habr.com/ru/post/1272239/


All Articles