From 1e14667bbce230964384b8756bf752c039bd2c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Fri, 9 Sep 2016 17:18:17 +0200 Subject: [PATCH] Don't compare foreign values to enumeration type Clang warns when comparing an enumeration type with a value not found in this enumeration: warning: comparison of constant VALUE with expression of type 'TYPE' is always false [-Wtautological-constant-out-of-range-compare] If the compiler then decides to optimize the test away because it assumes the it is indeed always false, it can lead to pretty subtle and nasty issues. Ported universal-ctags patch from Colomban Wendling --- ctags/parsers/c.c | 5 +++-- ctags/parsers/fortran.c | 5 +++-- ctags/parsers/go.c | 5 +++-- ctags/parsers/jscript.c | 5 +++-- ctags/parsers/php.c | 5 +++-- ctags/parsers/sql.c | 5 +++-- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ctags/parsers/c.c b/ctags/parsers/c.c index 54b6c6ff..6a631dc7 100644 --- a/ctags/parsers/c.c +++ b/ctags/parsers/c.c @@ -57,7 +57,7 @@ typedef enum eException /* Used to specify type of keyword. */ -typedef enum eKeywordId +enum eKeywordId { KEYWORD_ATTRIBUTE, KEYWORD_ABSTRACT, KEYWORD_ALIAS, KEYWORD_BOOLEAN, KEYWORD_BYTE, KEYWORD_BAD_STATE, KEYWORD_BAD_TRANS, @@ -92,7 +92,8 @@ typedef enum eKeywordId KEYWORD_USING, KEYWORD_VIRTUAL, KEYWORD_VOID, KEYWORD_VOLATILE, KEYWORD_WCHAR_T, KEYWORD_WEAK, KEYWORD_WHILE -} keywordId; +}; +typedef int keywordId; /* to allow KEYWORD_NONE */ /* Used to determine whether keyword is valid for the current language and * what its ID is. diff --git a/ctags/parsers/fortran.c b/ctags/parsers/fortran.c index 073622a3..c9df5524 100644 --- a/ctags/parsers/fortran.c +++ b/ctags/parsers/fortran.c @@ -61,7 +61,7 @@ typedef enum eFortranLineType { /* Used to specify type of keyword. */ -typedef enum eKeywordId { +enum eKeywordId { KEYWORD_allocatable, KEYWORD_assignment, KEYWORD_associate, @@ -140,7 +140,8 @@ typedef enum eKeywordId { KEYWORD_volatile, KEYWORD_where, KEYWORD_while -} keywordId; +}; +typedef int keywordId; /* to allow KEYWORD_NONE */ typedef enum eTokenType { TOKEN_UNDEFINED, diff --git a/ctags/parsers/go.c b/ctags/parsers/go.c index f908d0c6..385ad05c 100644 --- a/ctags/parsers/go.c +++ b/ctags/parsers/go.c @@ -27,7 +27,7 @@ * DATA DECLARATIONS */ -typedef enum eKeywordId { +enum eKeywordId { KEYWORD_package, KEYWORD_import, KEYWORD_const, @@ -38,7 +38,8 @@ typedef enum eKeywordId { KEYWORD_interface, KEYWORD_map, KEYWORD_chan -} keywordId; +}; +typedef int keywordId; /* to allow KEYWORD_NONE */ typedef enum eTokenType { TOKEN_NONE = -1, diff --git a/ctags/parsers/jscript.c b/ctags/parsers/jscript.c index 0b718e0f..c810376e 100644 --- a/ctags/parsers/jscript.c +++ b/ctags/parsers/jscript.c @@ -51,7 +51,7 @@ static stringList *FunctionNames; /* Used to specify type of keyword. */ -typedef enum eKeywordId { +enum eKeywordId { KEYWORD_function, KEYWORD_capital_function, KEYWORD_capital_object, @@ -72,7 +72,8 @@ typedef enum eKeywordId { KEYWORD_finally, KEYWORD_sap, KEYWORD_return -} keywordId; +}; +typedef int keywordId; /* to allow KEYWORD_NONE */ typedef enum eTokenType { TOKEN_UNDEFINED, diff --git a/ctags/parsers/php.c b/ctags/parsers/php.c index f8decca3..72389582 100644 --- a/ctags/parsers/php.c +++ b/ctags/parsers/php.c @@ -24,7 +24,7 @@ #define SCOPE_SEPARATOR "::" -typedef enum { +enum { KEYWORD_abstract, KEYWORD_and, KEYWORD_as, @@ -84,7 +84,8 @@ typedef enum { KEYWORD_while, KEYWORD_xor, KEYWORD_yield -} keywordId; +}; +typedef int keywordId; /* to allow KEYWORD_NONE */ typedef enum { ACCESS_UNDEFINED, diff --git a/ctags/parsers/sql.c b/ctags/parsers/sql.c index 8d358280..87380ba1 100644 --- a/ctags/parsers/sql.c +++ b/ctags/parsers/sql.c @@ -53,7 +53,7 @@ typedef enum eException { ExceptionNone, ExceptionEOF } exception_t; /* * Used to specify type of keyword. */ -typedef enum eKeywordId { +enum eKeywordId { KEYWORD_is, KEYWORD_begin, KEYWORD_body, @@ -126,7 +126,8 @@ typedef enum eKeywordId { KEYWORD_comment, KEYWORD_create, KEYWORD_go -} keywordId; +}; +typedef int keywordId; /* to allow KEYWORD_NONE */ typedef enum eTokenType { TOKEN_UNDEFINED,