From 39cd9987134ba2880059533b7a48c98bc8ce029b Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Mon, 25 Aug 2008 06:41:20 +0000 Subject: [PATCH] Partially implement -Wdeprecated-declarations. [r21426] --- ast.c | 9 +++++---- ast_t.h | 4 ++-- parser.c | 17 +++++++++-------- warning.c | 2 ++ warning.h | 4 +++- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/ast.c b/ast.c index b75a23a..3f597b3 100644 --- a/ast.c +++ b/ast.c @@ -1269,9 +1269,10 @@ static void print_ms_modifiers(const declaration_t *declaration) { decl_modifiers_t modifiers = declaration->modifiers; /* DM_FORCEINLINE handled outside. */ - if((modifiers & ~DM_FORCEINLINE) != 0 || - declaration->alignment != 0 || declaration->deprecated != 0 || - declaration->get_property_sym != NULL || declaration->put_property_sym != NULL) { + if ((modifiers & ~DM_FORCEINLINE) != 0 || + declaration->alignment != 0 || + declaration->get_property_sym != NULL || + declaration->put_property_sym != NULL) { char *next = "("; fputs("__declspec", out); @@ -1302,7 +1303,7 @@ static void print_ms_modifiers(const declaration_t *declaration) { if(modifiers & DM_NOINLINE) { fputs(next, out); next = ", "; fputs("noinline", out); } - if(declaration->deprecated != 0) { + if (modifiers & DM_DEPRECATED) { fputs(next, out); next = ", "; fputs("deprecated", out); if(declaration->deprecated_string != NULL) fprintf(out, "(\"%s\")", declaration->deprecated_string); diff --git a/ast_t.h b/ast_t.h index f51f840..0230f18 100644 --- a/ast_t.h +++ b/ast_t.h @@ -533,7 +533,8 @@ typedef enum decl_modifier_t { DM_CDECL = 1 << 20, DM_FASTCALL = 1 << 21, DM_STDCALL = 1 << 22, - DM_THISCALL = 1 << 23 + DM_THISCALL = 1 << 23, + DM_DEPRECATED = 1 << 24 } decl_modifier_t; typedef unsigned decl_modifiers_t; @@ -550,7 +551,6 @@ struct declaration_t { unsigned int address_taken : 1; unsigned int is_inline : 1; unsigned int used : 1; /**< Set if the declaration is used. */ - unsigned int deprecated : 1; /**< Microsoft or GNU deprecated attribute. */ type_t *type; symbol_t *symbol; source_position_t source_position; diff --git a/parser.c b/parser.c index 4925adf..2b0897d 100644 --- a/parser.c +++ b/parser.c @@ -1608,7 +1608,6 @@ static decl_modifiers_t parse_gnu_attribute(gnu_attribute_t **attributes) switch(kind) { case GNU_AK_CONST: case GNU_AK_VOLATILE: - case GNU_AK_DEPRECATED: case GNU_AK_NAKED: case GNU_AK_MALLOC: case GNU_AK_WEAK: @@ -1657,6 +1656,7 @@ static decl_modifiers_t parse_gnu_attribute(gnu_attribute_t **attributes) case GNU_AK_TRANSPARENT_UNION: modifiers |= DM_TRANSPARENT_UNION; goto no_arg; case GNU_AK_CONSTRUCTOR: modifiers |= DM_CONSTRUCTOR; goto no_arg; case GNU_AK_DESTRUCTOR: modifiers |= DM_DESTRUCTOR; goto no_arg; + case GNU_AK_DEPRECATED: modifiers |= DM_DEPRECATED; goto no_arg; case GNU_AK_ALIGNED: /* __align__ may be used without an argument */ @@ -3991,7 +3991,6 @@ static declaration_t *parse_declarator( declaration_t *const declaration = allocate_declaration_zero(); declaration->declared_storage_class = specifiers->declared_storage_class; declaration->modifiers = specifiers->modifiers; - declaration->deprecated = specifiers->deprecated; declaration->deprecated_string = specifiers->deprecated_string; declaration->get_property_sym = specifiers->get_property_sym; declaration->put_property_sym = specifiers->put_property_sym; @@ -5769,18 +5768,20 @@ static expression_t *parse_reference(void) declaration->used = true; /* check for deprecated functions */ - if (declaration->deprecated != 0) { - const char *prefix = ""; - if (is_type_function(declaration->type)) - prefix = "function "; + if (warning.deprecated_declarations && + declaration->modifiers & DM_DEPRECATED) { + char const *const prefix = is_type_function(declaration->type) ? + "function" : "variable"; if (declaration->deprecated_string != NULL) { warningf(&source_position, - "%s'%Y' was declared 'deprecated(\"%s\")'", prefix, declaration->symbol, + "%s '%Y' is deprecated (declared %P): \"%s\"", prefix, + declaration->symbol, &declaration->source_position, declaration->deprecated_string); } else { warningf(&source_position, - "%s'%Y' was declared 'deprecated'", prefix, declaration->symbol); + "%s '%Y' is deprecated (declared %P)", prefix, + declaration->symbol, &declaration->source_position); } } diff --git a/warning.c b/warning.c index ae1223f..5aa8aa9 100644 --- a/warning.c +++ b/warning.c @@ -24,6 +24,7 @@ warning_t warning = { .attribute = true, .char_subscripts = true, + .deprecated_declarations = true, .empty_statement = false, .fatal_errors = false, .float_equal = false, @@ -92,6 +93,7 @@ void set_warning_opt(const char *const opt) } OPT("attribute", attribute); OPT("char-subscripts", char_subscripts); + OPT("deprecated-declarations", deprecated_declarations); OPT("empty-statement", empty_statement); OPT("error", s_are_errors); OPTX("extra") { diff --git a/warning.h b/warning.h index 196f43f..24ae114 100644 --- a/warning.h +++ b/warning.h @@ -38,7 +38,9 @@ typedef struct warning_t { bool cast_qual:1; /**< Warn whenever a pointer is cast so as to remove a type qualifier from the target type */ bool conversion:1; /**< Warn if a prototype causes a type conversion that is different from what would happen to the same argument in the absence of a prototype */ bool declaration_after_statement:1; /**< Warn when a declaration is found after a statement in a block */ - bool deprecated_declarations:1; /**< Warn about uses of functions, variables and types marked as deprecated by using the 'deprecated' attribute */ +#endif + bool deprecated_declarations:1; /* TODO implement for types */ /**< Warn about uses of functions, variables and types marked as deprecated by using the 'deprecated' attribute */ +#if 0 // TODO bool div_by_zero:1; /**< Warn about compile-time integer division by zero */ #endif bool empty_statement:1; /**< Warn about empty statements, i.e. lone ';' */ -- 2.20.1