Const QList <int> warnings = QList <int> () << 0; segfaults with gcc 4.7.2

Thus, the code mentioned in the subject line causes a segmentation error with Qt 4.8.3 and gcc 4.7.2

This is outside of any classes / structures in the .cpp file and works with gcc 4.4

 const QList<int> warnings = QList<int>() << 0 << 3 << 7; 

The tracks give the following two clues:

 __do_global_ctors() __static_initialization_and_destruction_0 

So it seems that the β€œwarning” is not yet available when it inserts the last list into it.

Works with 4.7.2 if I change it to the following:

 global scope: QList< int> warnings; 

This is some function:

 warnings = QList<int>() << 0 << 3; 

I wonder why this is happening?

Edit:

I assume that initially I cut out too much material from my question, but warnings should be const in the file area (.cpp-file) to store enumerations in the form of bouquets.

+4
source share
1 answer

My psychic debugging abilities tell me that this line exists in the global / file area, and not in the class / function area. Thus, your line can be called at any time during static initialization. With your old gcc, it so happened that QT was initialized before your line was called. With the new gcc, he reordered (completely legal) static init to call your function first before QT was ready to create objects and insert objects into them.

The solution is to hold back on creating a QList until main begins. Using pointers or static local objects are two common implementations.

+6
source

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


All Articles