arocc icon indicating copy to clipboard operation
arocc copied to clipboard

Improve error for assigning to const

Open Vexu opened this issue 3 years ago • 0 comments

int foo(void) {
    const int a;
    a = 1;
    return a;
}

Arocc output:

./a.c:40:7: error: expression is not assignable
    a = 1;
      ^
1 error generated.

Clang output:

a.c:40:7: error: cannot assign to variable 'a' with const-qualified type 'const int'
    a = 1;
    ~ ^
a.c:39:15: note: variable 'a' declared const here
    const int a;
    ~~~~~~~~~~^
1 error generated.

Vexu avatar Nov 17 '22 14:11 Vexu