Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Pre-increment on pointer to struct causes error #500

Open
ryankeleti opened this issue Aug 9, 2020 · 0 comments
Open

Pre-increment on pointer to struct causes error #500

ryankeleti opened this issue Aug 9, 2020 · 0 comments
Labels
analyzer Issue with semantic analysis bug Something isn't working

Comments

@ryankeleti
Copy link
Contributor

ryankeleti commented Aug 9, 2020

When attempting to pre-increment a pointer to a struct, compiler throws error that operation is not between arithmetic types or a pointer operation.

Code

typedef struct {
  int i;
} s;

int main() {
  s *x;
  ++x;
}

Error

struct.c:7:3 error: invalid program: invalid operators for '+' (expected either arithmetic types or pointer operation, got 'struct {
    int i;
} * + struct {
    int i;
} *'
  ++x;
  ^^
1 error generated

Potential cause of error, paraphrasing @jyn514 here: It thinks that it's adding a 1 of type pointer, but it's adding a 1 of type integer here. This is a bug in desugaring complex assignment then here. It needs to be smart and only cast if it would be valid.

@jyn514 jyn514 added analyzer Issue with semantic analysis bug Something isn't working labels Aug 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
analyzer Issue with semantic analysis bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants