-2

While debugging something I stumbled into this behavior on godbolt. When compiling and running the following (godbolt link https://godbolt.org/z/9c5966sbK):

#include <array>

int main()
{
    std::array<int, 4> arr{1,2,3,4};
    int val = arr.at(5);
    return val;
}

using latest x86 versions of gcc, clang and msvc, with optimizations disabled (-O0 and /Od resp.) msvc doesn't throw std::out_of_range exception.

Why does this happen?

13
  • 1
    Ahhh, facepalm. You're right. After fixing that I still get wrong result from msvc though Commented Feb 24 at 21:45
  • 1
    There is no "Wrong result" when you don't catch the exception. The return value from the MSVC execution is a clue that something went wrong. Commented Feb 24 at 21:47
  • 1
    3221225595 -> C000007B -> STATUS_INVALID_IMAGE_FORMAT. Looks like Compiler explorer ran into DLL hell and tried a 64 bit DLL. Commented Feb 24 at 21:53
  • 2
    @TedLyngmo Ahh sorry, right. Thank you for clearing it up. Good to know I was just being a clown and there is no need to have an existential crisis. Commented Feb 24 at 21:53
  • 6
    @alfC They are not UB tho? It's defined that if if exception leaves main(), std::terminate is called. It's implementation- (and OS-) defined how that is handled, but it's not UB. Commented Feb 25 at 9:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.