From: Michael Beck Date: Mon, 2 Jun 2008 11:32:06 +0000 (+0000) Subject: add option -Wreturn-type X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=92aef485912254eb5b4914101d4fc06f6b64ed64;hp=9ab9ba303994ecb258aaf7ecb5b1a0ae4808e91f;p=cparser add option -Wreturn-type [r19923] --- diff --git a/ast2firm.c b/ast2firm.c index fe849fe..c09a7c5 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -38,6 +38,7 @@ #include "diagnostic.h" #include "lang_features.h" #include "types.h" +#include "warning.h" #include "driver/firm_opt.h" #include "driver/firm_cmdline.h" @@ -4974,9 +4975,11 @@ static void create_function(declaration_t *declaration) in[0] = new_Const(mode, get_mode_null(mode)); } else { in[0] = new_Unknown(mode); - warningf(&declaration->source_position, "missing return statement at end of non-void function '%Y'", - declaration->symbol); - + if(warning.return_type) { + warningf(&declaration->source_position, + "missing return statement at end of non-void function '%Y'", + declaration->symbol); + } } ret = new_Return(get_store(), 1, in); } diff --git a/warning.c b/warning.c index c93ed20..42b47b4 100644 --- a/warning.c +++ b/warning.c @@ -46,7 +46,8 @@ warning_t warning = { .unused_label = false, .unused_parameter = false, .unused_value = true, - .unused_variable = false + .unused_variable = false, + .return_type = true }; void set_warning_opt(const char *const opt) @@ -85,6 +86,7 @@ void set_warning_opt(const char *const opt) SET(unused_parameter) SET(unused_value) SET(unused_variable) + SET(return_type) } OPT("attribute", attribute) OPT("char-subscripts", char_subscripts) @@ -135,6 +137,7 @@ void set_warning_opt(const char *const opt) OPT("unused-parameter", unused_parameter) OPT("unused-value", unused_value) OPT("unused-variable", unused_variable) + OPT("return-type", return_type) #undef OPT #undef SET #undef OPT_X diff --git a/warning.h b/warning.h index 3b3f22f..ef5596a 100644 --- a/warning.h +++ b/warning.h @@ -104,6 +104,9 @@ typedef struct warning_t { #if 0 // TODO bool write_strings:1; /**< Give string constants the type 'const char[LENGTH]' so that copying the address of one into a 'char *' pointer will get a warning */ #endif + bool return_type:1; /**< Warn whenever a function is defined with a return-type that + defaults to `int'. Also warn about any `return' statement with no + return-value in a function whose return-type is not `void'. */ } warning_t; extern warning_t warning;