mewmew/uc

semantics: Think carefully about how to handle tentative declaration

mewmew opened this issue · 2 comments

Related to issue #50.

Last tentative definition becomes the definition, unless defined explicitly (e.g. having an initializer).

Examples from GCC demonstrating this behaviour.

Contents of a.c:

int x;
int x;

char x;
u@x1 ~/Desktop> gcc -o a a.c
a.c:4:6: error: conflicting types for ‘x’
 char x;
      ^
a.c:2:5: note: previous declaration of ‘x’ was here
 int x;
     ^

Contents of a.c:

int x;
int x = 2;

char x;
u@x1 ~/Desktop> gcc -o a a.c
a.c:4:6: error: conflicting types for ‘x’
 char x;
      ^
a.c:2:5: note: previous definition of ‘x’ was here
 int x = 2;
     ^

Contents of a.c:

int x = 2;
int x;

char x;
u@x1 ~/Desktop> gcc -o a a.c
a.c:4:6: error: conflicting types for ‘x’
 char x;
      ^
a.c:1:5: note: previous definition of ‘x’ was here
 int x = 2;
     ^

The scope handling of the semantic analysis takes tentative declarations into account. Should a specific issue arise in the future, then simply open a new issue with a bug label. Closing this issue for now.