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

Serious apparent bug when allocating byte-objects with new[] and constructors

$
0
0

Hi,

Here is a simple example:

#include <cstdint>

class Foo final {
    public:
        uint8_t packed;

    public:
        inline Foo(void) : packed(0xFF) {} //causes error
        inline ~Foo(void) = default;
};
static_assert(sizeof(Foo)==sizeof(uint8_t),"Implementation error!");

int main(int /*argc*/, char* /*argv*/[]) {
    Foo* arr = new Foo[4]; //Tried a bunch of different sizes.  All fail.
    delete [] arr;

    return 0;
}

This program is valid C++, yet erroneously corrupts its own memory when run, and crashes. The constructor line appears to be the culprit. The program was compiled with Intel C++ 16.0.

For your convenience, here is a link to a complete solution that demonstrates the problem. Here is a link to the assembled code.

-i


Viewing all articles
Browse latest Browse all 1616

Trending Articles



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