thradams / cake

Cake a C23 front end and transpiler written in C
http://thradams.com/cake/index.html
GNU General Public License v3.0
533 stars 21 forks source link

Incorrect diagnostic: assignment to expression with array type #149

Closed iphydf closed 6 months ago

iphydf commented 6 months ago
void foo(char x[10]) {
    char y[10];
    x = y;                                                                                                                                  
}

This should be fine. x is actually a pointer parameter, and y can decay to a pointer. It's useful for static analysis to treat the [10] as array in some cases, but this assignment should be allowed.

thradams commented 6 months ago

Actually this was on purpose.. but in this case I may change the category instead of warning "note".

But I need to check.. because the style warning I was talking about is this code

void foo(char x[10]) {
    x = 0;                                                                                                                                  
}
iphydf commented 6 months ago

I guess that makes sense. Assigning params is a bad idea anyway. I'll refactor my code. No need to fix this.

thradams commented 6 months ago

I agree that something is wrong..it could be an error.

thradams commented 6 months ago
int main(){
  int a[2];
  int b[2];
  a = b; //this is where the error is correct.
}
iphydf commented 6 months ago

Yes, that's a 100% correct error because that code is invalid. In the parameter case, it's valid C code, but I'd argue nobody should write that code. It's better to have a local pointer variable and assign the parameter to that.