dimanche 30 octobre 2016

std::array - 'buffer of size n will be overrun', only in VS

constexpr auto CHUNKS_X = 5, CHUNKS_Y = 5, CHUNKS_Z = 1;
std::array<std::bitset<CHUNKS_X>, CHUNKS_Y> ys;
std::array<decltype(ys), CHUNKS_Z> zs;
if (CHUNKS_Z > 1)
{
    zs[0] = ys;
    //zs.at(1) = ys; //this works
    zs[1] = ys; //this doesn't work
    for (auto &x : zs[1])
    {
        x.flip();
    }
    for (auto z = 2; z < CHUNKS_Z; z++)
    {
        zs[z] = zs[z - 2];
    }
}

The line zs[1] = ys; gives me

error C4789: buffer 'zs' of size 20 bytes will be overrun; 20 bytes will be written starting at offset 20

But only when compiling in VS. Compiling on the command line gives me no such error, nor does using zs.at(1) = ys; instead. Another thing of note is that MSDN says that this should be a warning, not an error.

I realize this might be a subtle compiler flag issue but I haven't the slightest clue where to start looking.

Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86

Aucun commentaire:

Enregistrer un commentaire