diff --git a/error.c b/error.c index e6fcac42..3490b587 100644 --- a/error.c +++ b/error.c @@ -4,6 +4,7 @@ #include #include #include "8cc.h" +#include bool enable_warning = true; bool warning_is_error = false; diff --git a/parse.c b/parse.c index e11bf773..827748ff 100644 --- a/parse.c +++ b/parse.c @@ -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; @@ -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; diff --git a/test/auto.c b/test/auto.c new file mode 100644 index 00000000..3019fe30 --- /dev/null +++ b/test/auto.c @@ -0,0 +1,7 @@ +#include "test.h" + +void testmain() { +print("test auto at the global scope(should return a warn)"); +} + +auto x = 0; diff --git a/test/register.c b/test/register.c new file mode 100644 index 00000000..f745a49e --- /dev/null +++ b/test/register.c @@ -0,0 +1,9 @@ +#include "test.h" + +void testmain() { +print("register at global scope(should invoke a warn)"); +} + +register int a = 0; + +