[PATCH] eliminate insane conversions from int to enum

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Saturday 27 of March 2010 10:29:50 Josh Triplett wrote:
> > Here is what sparse gives:
> > $ ./sparse enum.c
> > enum.c:1:10: warning: non-ANSI function declaration of function 'main'
> > enum.c:6:15: warning: conversion of
> > enum.c:6:15:     int to
> > enum.c:6:15:     int enum <noident>
> >
> >
> > Here is what g++ gives:
> > $ g++ enum.c
> > enum.c: In function ‘int main()’:
> > enum.c:6: error: invalid conversion from ‘int’ to ‘main()::<anonymous
> > enum>’
>
> Yup, both of these warnings seem correct.  Don't fix them by casting,
> fix them by declaring "val" with an appropriate integral type.

patch attached

Kamil
From 44d964b9479affff31ad5690bedfe580ee3b50fa Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@xxxxxxxxxx>
Date: Sat, 27 Mar 2010 10:48:34 +0100
Subject: [PATCH] eliminate insane conversions from int to enum


Signed-off-by: Kamil Dudka <kdudka@xxxxxxxxxx>
---
 expression.h |    1 -
 parse.c      |    2 +-
 parse.h      |    2 ++
 symbol.c     |    4 ++--
 symbol.h     |    8 ++++----
 5 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/expression.h b/expression.h
index 81f70ad..fe08a5f 100644
--- a/expression.h
+++ b/expression.h
@@ -206,7 +206,6 @@ static inline int lookup_type(struct token *token)
 }
 
 /* Statement parsing */
-struct statement *alloc_statement(struct position pos, int type);
 struct token *initializer(struct expression **tree, struct token *token);
 struct token *compound_statement(struct token *, struct statement *);
 
diff --git a/parse.c b/parse.c
index 7c6dce7..adaa132 100644
--- a/parse.c
+++ b/parse.c
@@ -613,7 +613,7 @@ static int SENTINEL_ATTR match_idents(struct token *token, ...)
 }
 
 
-struct statement *alloc_statement(struct position pos, int type)
+struct statement *alloc_statement(struct position pos, enum statement_type type)
 {
 	struct statement *stmt = __alloc_statement(0);
 	stmt->type = type;
diff --git a/parse.h b/parse.h
index 02b8585..6d51726 100644
--- a/parse.h
+++ b/parse.h
@@ -115,6 +115,8 @@ struct statement {
 	};
 };
 
+struct statement *alloc_statement(struct position pos, enum statement_type type);
+
 extern struct symbol_list *function_computed_target_list;
 extern struct statement_list *function_computed_goto_list;
 
diff --git a/symbol.c b/symbol.c
index 96dfbfa..8c46e20 100644
--- a/symbol.c
+++ b/symbol.c
@@ -39,12 +39,12 @@ void access_symbol(struct symbol *sym)
 	}
 }
 
-struct symbol *lookup_symbol(struct ident *ident, enum namespace ns)
+struct symbol *lookup_symbol(struct ident *ident, int ns_mask)
 {
 	struct symbol *sym;
 
 	for (sym = ident->symbols; sym; sym = sym->next_id) {
-		if (sym->namespace & ns) {
+		if (sym->namespace & ns_mask) {
 			sym->used = 1;
 			return sym;
 		}
diff --git a/symbol.h b/symbol.h
index e567305..7921aa1 100644
--- a/symbol.h
+++ b/symbol.h
@@ -97,7 +97,7 @@ struct decl_state {
 };
 
 struct symbol_op {
-	enum keyword type;
+	int type;
 	int (*evaluate)(struct expression *);
 	int (*expand)(struct expression *, int);
 	int (*args)(struct expression *);
@@ -267,7 +267,7 @@ extern void access_symbol(struct symbol *);
 extern const char * type_difference(struct ctype *c1, struct ctype *c2,
 	unsigned long mod1, unsigned long mod2);
 
-extern struct symbol *lookup_symbol(struct ident *, enum namespace);
+extern struct symbol *lookup_symbol(struct ident *, int ns_mask);
 extern struct symbol *create_symbol(int stream, const char *name, int type, int namespace);
 extern void init_symbols(void);
 extern void init_ctype(void);
@@ -367,11 +367,11 @@ static inline int get_sym_type(struct symbol *type)
 	return type->type;
 }
 
-static inline struct symbol *lookup_keyword(struct ident *ident, enum namespace ns)
+static inline struct symbol *lookup_keyword(struct ident *ident, int ns_mask)
 {
 	if (!ident->keyword)
 		return NULL;
-	return lookup_symbol(ident, ns);
+	return lookup_symbol(ident, ns_mask);
 }
 
 #define is_restricted_type(type) (get_sym_type(type) == SYM_RESTRICT)
-- 
1.7.0.2


[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux