Crash in C++ code due to undefined behaviour or compiler bug?

后端 未结 3 1946
夕颜
夕颜 2021-02-19 01:15

I am experiencing strange crashes. And I wonder whether it is a bug in my code, or the compiler. When I compile the following C++ code with Microsoft Visual Studio 2010 as an op

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-19 01:39

    It doesn't have to be UB or compiler bug. It can be neither due to the way that VS2010 was produced.

    Strictly speaking, your program exhibits well-defined behaviour. However, that might only be according to the newest C++ Standard. VS2010 is only implemented against a draft Standard which may not have included this provision. If it did not, then your code is not UB, but VS is not incorrect to produce UB, as those were the requirements of the time it was made.

    Of course, if it's been legal to treat stack objects as an array of one object in C++03, then it is a compiler bug.

    Edit: If you still get the crash for an array as you state, then that is definitely a compiler bug.

提交回复
热议问题