Empty structs throw a compiler error instead of crashing the vm. (bug 5475, r=dvander).
authorMichael Busby <mibusby@gmail.com>
Tue Sep 04 21:03:22 2012 -0700 (2012-09-04)
changeset 180b98a56a533d0
parent 179 5f3c91fa6058
child 181 e731795f925c
Empty structs throw a compiler error instead of crashing the vm. (bug 5475, r=dvander).
src/Messages.tbl
src/Parser.cpp
     1.1 --- a/src/Messages.tbl	Thu Sep 13 23:58:22 2012 -0700
     1.2 +++ b/src/Messages.tbl	Tue Sep 04 21:03:22 2012 -0700
     1.3 @@ -73,4 +73,4 @@
     1.4  MSG(CaseMustBeConstant,             SyntaxError,            "case expression must be a constant")
     1.5  MSG(CaseHasSameValue,               SyntaxError,            "case value appears twice in the same switch")
     1.6  MSG(CaseMustBeInteger,              SyntaxError,            "switch may only operate on integer values")
     1.7 -
     1.8 +MSG(StructCantBeEmpty,              SyntaxError,            "struct cannot be declared without any fields")
     2.1 --- a/src/Parser.cpp	Thu Sep 13 23:58:22 2012 -0700
     2.2 +++ b/src/Parser.cpp	Tue Sep 04 21:03:22 2012 -0700
     2.3 @@ -1126,6 +1126,11 @@
     2.4      if (!expect(TOK_RBRACE))
     2.5          return NULL;
     2.6  
     2.7 +    if (fields->empty()) {
     2.8 +        cc_.reportError(pos, Message_StructCantBeEmpty);
     2.9 +        return NULL;
    2.10 +    }
    2.11 +
    2.12      return new (pool_) StructureStatement(pos, type, fields);
    2.13  }
    2.14