lundi 9 septembre 2019

std::shared_ptr

The current C++ compilers fail to find a suitable overload for std::shared_ptr when using a C-array as a type.

I can make it a real std::array object and that works, but the library I'm linking against (fftw3) has already created the typedef and uses it in all of it's C-API calls.

#include <memory>
typedef double fftw_complex[2];

int main(int argc, char* argv[])
{
        fftw_complex bob; //works fine
        bob[0]=2; bob[1]=-1; //works fine
        std::shared_ptr<fftw_complex> handle; //works fine
        std::shared_ptr<double> other(new double[35]); //works fine
        handle = std::shared_ptr<fftw_complex>(new fftw_complex[35]);//can't find constructor
        return 0;
}

Up until a few months ago this worked fine with all compilers. With the update to gcc to version 7.3, 8.2, and 9 I now get an error when trying to compile the non-void constructor. I suspect it is because of the "improvements" to std::shared_ptr to automatically handle when T is an array type.

Aucun commentaire:

Enregistrer un commentaire