Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

ICC 16.0.2 fails at runtime when allocating array of std::shared_ptr objects

$
0
0

The Windows ICC 16.0.2 compiler (using VS2015 update 1) is failing at run time when allocating an array of shared_ptr.  The error is an Access Violation.  Meanwhile, compiling with just the msvc compiler worked.

Stepping through the code didn’t show anything obvious.  So I tried converting the raw array of shared_ptr  (*shared_ptr<T>) to a std::vector of shared_ptr (std::vector<std::shared_ptr<T>>.  I was able to move forward in execution.  But I ended up crashing later due to the same issue in another piece of code.

This is very strange, so I tried writing a trivial program that isolates the code.  Sure enough, the program crashes whenever I try to allocate an array of shared_ptr<T> (regardless of type).  See below.

Trivial Program:

#include <memory>
#include <random>

class Foo {
    int A;
    int B;
    int C[13];
};

//using MyTypeSP = Foo; //Works
//using MyTypeSP = std::shared_ptr<Foo>; //Fails, ACCESS VIOLATION
//using MyTypeSP = std::shared_ptr<int>; //Fails, ACCESS VIOLATION
//using MyTypeSP = std::vector<int>; //Works
using MyTypeSP = int; //Works

int main() {
    const int count = rand() % 50;
    MyTypeSP *m_pMCIDs;
    m_pMCIDs = new MyTypeSP[count];

    return 0;
}

Can anybody else repeat this behavior?


Viewing all articles
Browse latest Browse all 1616

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>