[3/3] fix enum typing
diff mbox

Message ID 20180418153959.33271-4-luc.vanoostenryck@gmail.com
State Under Review
Headers show

Commit Message

Luc Van Oostenryck April 18, 2018, 3:39 p.m. UTC
Currently, type_difference() doesn't make a distinction between
enums & ints with the result being that sparse is not only way
too permissive regarding the typing of enums but simply wrong.

Fix this in type_difference() by:
*) stop to strip SYM_ENUM as it is (and must be) done with SYM_NODE.
*) be as strict with SYM_ENUMs as with SYM_STRUCTs & SYM_UNIONs.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 evaluate.c                 | 5 +++--
 validation/typediff-enum.c | 1 -
 2 files changed, 3 insertions(+), 3 deletions(-)

Patch
diff mbox

diff --git a/evaluate.c b/evaluate.c
index 0d50220a6..b7be8a409 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -695,7 +695,7 @@  const char *type_difference(struct ctype *c1, struct ctype *c2,
 		if (!t1 || !t2)
 			return "different types";
 
-		if (t1->type == SYM_NODE || t1->type == SYM_ENUM) {
+		if (t1->type == SYM_NODE) {
 			t1 = base1;
 			move1 = 1;
 			if (!t1)
@@ -703,7 +703,7 @@  const char *type_difference(struct ctype *c1, struct ctype *c2,
 			continue;
 		}
 
-		if (t2->type == SYM_NODE || t2->type == SYM_ENUM) {
+		if (t2->type == SYM_NODE) {
 			t2 = base2;
 			move2 = 1;
 			if (!t2)
@@ -724,6 +724,7 @@  const char *type_difference(struct ctype *c1, struct ctype *c2,
 			return "bad types";
 		case SYM_RESTRICT:
 			return "different base types";
+		case SYM_ENUM:
 		case SYM_UNION:
 		case SYM_STRUCT:
 			/* allow definition of incomplete structs and unions */
diff --git a/validation/typediff-enum.c b/validation/typediff-enum.c
index 4c97bcf6c..6c7b37acf 100644
--- a/validation/typediff-enum.c
+++ b/validation/typediff-enum.c
@@ -56,7 +56,6 @@  static struct ops ops_ko = {
 
 /*
  * check-name: typediff-enum
- * check-known-to-fail
  *
  * check-error-start
 typediff-enum.c:5:5: error: symbol 'v' redeclared with different type (originally declared at typediff-enum.c:4) - different base types