Segmentation fault sometimes occurs in a program when icpc is used.
The version of icpc I am using is 17.0.2 20170213, and the version of g++ is 5.2.0.
It does not happen when g++ is used.
This issue was originally found in BOUT++ code. (https://github.com/boutproject/BOUT-dev)
Please have a look at the attached reproducer.
It was written based on BOUT++ code.
If g++ is used:
But if icpc is used:
Segmentation fault (core dumped)
Please note that sometimes the segfault does not occur, but always the output is corrupted.(0 0 0....)
The problem does not happen even if icpc is used when
1) a copy constructor is defined (a.out.intel.copy)
2) reference variables are not used (a.out.intel.noref)
Though this issue had been fixed in BOUT++ code by doing 2) (https://github.com/boutproject/BOUT-dev/pull/468), but I still suspect this is a bug of intel compiler because the problem does not happen with g++.
Is this a bug of icpc?
This looks like a user error. A copy constructor is needed to keep the reference data members valid.
DataIterator has several self-references, but no copy constructor to keep them consistent. And of course all the member functions of Test return an object of type DataIterator. At what do those references wind up pointing if the member functions aren’t inlined?