Forum Stats

  • 3,875,875 Users
  • 2,266,977 Discussions


Bug with switch statements and iterator reference

I believe I have found a bug in the Developer Studio 12.6 compiler. I've included a tar file which contains the file that triggers the bug (bad.cxx) and a workaround (good.cxx). Basically, if you try to reference-iterate over a vector inside a switch statement, the created reference is invalid, resulting in a segfault. bad.cxx demonstrates this. Iterating inside an if statement instead does not trigger the bug. good.cxx demonstrates this. I was able to reproduce this on Solaris 11 on both SPARC and x86. I did not try it on Linux.