0

I got a segmentation fault for this code in GCC but compiles fine with MSVC

QMap<int, QPair<QString, QString>> someData; 
// inserting some value
for (auto id : someData.keys()) {
   auto [foo, bar] = someData[id];
   //do stuff with foo, bar.
}

And the structured binding emits a segfault.

Log:

internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.

Solution

declare the structured binding as reference.

auto& [foo, bar] = someData[id];

It looks like GCC cannot deduce the qualifiers, since operator[] returns a T&.

Bako
  • 313
  • 1
  • 15

0 Answers0