Skip to content

[BUG] Type deduction deduces a pointer from an int #1347

@threeifbyair

Description

@threeifbyair

When creating a variable using >> or & on an integral type, somehow the deduced type is some kind of pointer rather than an integer.

https://cpp2.godbolt.org/z/sf4Y7MxMz

bar: (foo: uint32_t) -> uint32_t = {
    x := foo >> 16;
    y := foo & 0xFFFF;
    return (x+1) ^ (y-1);
}

gives

example.cpp2(4,22): error: - - pointer arithmetic is illegal - use std::span or gsl::span instead
  ==> program violates bounds safety guarantee - see previous errors

If I explicitly say that y is a uint32_t, everything is fine, but why does cppfront think that it's a pointer?
(I've seen the same issue with x, but it doesn't reproduce in this example.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions