hsutter / cppfront

A personal experimental C++ Syntax 2 -> Syntax 1 compiler
Other
5.39k stars 232 forks source link

[BUG] Incorrect enum syntax crashes compiler #895

Closed JakeShirley closed 8 months ago

JakeShirley commented 8 months ago

Describe the bug I am still cludging my way around enums and typed in some nonsense. I got a really unhelpful message that doesn't help narrow down where the problem is.

To Reproduce

  1. Compile this example:

    Operation : @enum type = {
    None = 0;
    LessThan = 1;
    GreaterThan = 2;
    }
    auto main() -> int {
    std::cout << "Hello ";
    }
  2. See the following output:

    Bounds safety violation: out of bounds access attempt detected - attempted index 0, [min,max] range is [0,-1]
    terminate called without an active exception
    Program terminated with signal: SIGSEGV

Additional context Ideally cppfront would not crash. Or it would give a hint at where it was crashing.

hsutter commented 8 months ago

Thanks! Fixed.

That was Cpp2's on-by-default general subscript bounds checking catching a bug in self-hosted Cpp2 code that was indexing [0] on an empty container. I really like having bounds and null-deref checking on by default... I'm pretty careful about defensive checking, but seeing these bounds checks still catch bugs in my own code is a bit of an eye-opener.