shithub: mc

Download patch

ref: 1db8622646327359d06877fb85534a33cfa5ad6b
parent: f78dafbaa956467530295bba1caeaa61e783f274
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Aug 11 18:45:11 EDT 2016

Error if we duplicate struct members.

--- a/parse/type.c
+++ b/parse/type.c
@@ -291,10 +291,23 @@
 Type *mktystruct(Srcloc loc, Node **decls, size_t ndecls)
 {
 	Type *t;
+	Htab *ht;
+	int i;
+	char *s;
 
 	t = mktype(loc, Tystruct);
 	t->nsub = 0;
 	t->nmemb = ndecls;
+
+	ht = mkht(strhash, streq);
+	for (i = 0; i < ndecls; i++) {
+		s = declname(decls[i]);
+		if (hthas(ht, s))
+			fatal(decls[i], "duplicate struct member %s\n", declname(decls[i]));
+		htput(ht, s, s);
+	}
+	htfree(ht);
+
 	t->sdecls = memdup(decls, ndecls * sizeof(Node *));
 	return t;
 }