Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions error.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h>
#include <unistd.h>
#include "8cc.h"
#include<stdio.h>

bool enable_warning = true;
bool warning_is_error = false;
Expand Down
8 changes: 6 additions & 2 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ static Map *env() {
return localenv ? localenv : globalenv;
}

static bool islocalenv() {
return localenv ? true : false;
}

static Node *make_ast(Node *tmpl) {
Node *r = malloc(sizeof(Node));
*r = *tmpl;
Expand Down Expand Up @@ -2057,8 +2061,8 @@ static Type *read_decl_spec(int *rsclass) {
case KTYPEDEF: if (sclass) goto err; sclass = S_TYPEDEF; break;
case KEXTERN: if (sclass) goto err; sclass = S_EXTERN; break;
case KSTATIC: if (sclass) goto err; sclass = S_STATIC; break;
case KAUTO: if (sclass) goto err; sclass = S_AUTO; break;
case KREGISTER: if (sclass) goto err; sclass = S_REGISTER; break;
case KAUTO: if (sclass) goto err; sclass = S_AUTO; if(!islocalenv()) warnt(tok,"auto specifer should not at the global scope"); break;
case KREGISTER: if (sclass) goto err; sclass = S_REGISTER; if(!islocalenv()) warnt(tok,"register specifer should not at the global scope"); break;
case KCONST: break;
case KVOLATILE: break;
case KINLINE: break;
Expand Down
7 changes: 7 additions & 0 deletions test/auto.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "test.h"

void testmain() {
print("test auto at the global scope(should return a warn)");
}

auto x = 0;
9 changes: 9 additions & 0 deletions test/register.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "test.h"

void testmain() {
print("register at global scope(should invoke a warn)");
}

register int a = 0;