(C++) patch to catch implicit int
Jason Merrill
jason@cygnus.com
Sun Nov 22 23:21:00 GMT 1998
We have been lax about diagnosing implicit int on functions, even with
-pedantic. This is clear given the number of testcases I had to fix after
making this change: about 400. Fortunately s/^main/int main/ did most of
the work for me.
This patch still allows implicit int on the definition of main, unless
-pedantic or -Wreturn-type are specified.
1998-11-22 Jason Merrill <jason@yorick.cygnus.com>
* decl.c: Lose warn_about_return_type.
(grokdeclarator): Always complain about implicit int, except for
`main () { ... }'.
Index: decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.269
diff -c -p -r1.269 decl.c
*** decl.c 1998/11/22 21:34:24 1.269
--- decl.c 1998/11/23 07:17:02
*************** int current_function_returns_null;
*** 509,519 ****
tree current_function_return_value;
- /* Set to nonzero by `grokdeclarator' for a function
- whose return type is defaulted, if warnings for this are desired. */
-
- static int warn_about_return_type;
-
/* Nonzero means give `double' the same size as `float'. */
extern int flag_short_double;
--- 509,514 ----
*************** grokdeclarator (declarator, declspecs, d
*** 9117,9140 ****
}
else
{
! if (funcdef_flag)
! {
! if (warn_return_type
! && return_type == return_normal)
! /* Save warning until we know what is really going on. */
! warn_about_return_type = 1;
! }
! else if (RIDBIT_SETP (RID_TYPEDEF, specbits))
! pedwarn ("ANSI C++ forbids typedef which does not specify a type");
! else if (innermost_code != CALL_EXPR || pedantic
! || (warn_return_type && return_type == return_normal))
! {
! if (innermost_code == CALL_EXPR)
! cp_pedwarn ("return-type of `%D' defaults to `int'", dname);
! else
! cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type",
! dname);
! }
type = integer_type_node;
}
}
--- 9112,9127 ----
}
else
{
! if (! pedantic && ! warn_return_type
! && funcdef_flag
! && MAIN_NAME_P (dname)
! && ctype == NULL_TREE
! && in_namespace == NULL_TREE
! && current_namespace == global_namespace)
! /* Let `main () { }' slide, since it's so common. */;
! else
! cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type",
! dname);
type = integer_type_node;
}
}
*************** start_function (declspecs, declarator, a
*** 12482,12488 ****
/* Assume, until we see it does. */
current_function_returns_value = 0;
current_function_returns_null = 0;
- warn_about_return_type = 0;
named_labels = 0;
shadowed_labels = 0;
current_function_assigns_this = 0;
--- 12469,12474 ----
*************** start_function (declspecs, declarator, a
*** 12597,12603 ****
pedwarn ("return type for `main' changed to `int'");
TREE_TYPE (decl1) = fntype = default_function_type;
}
- warn_about_return_type = 0;
}
}
--- 12583,12588 ----
*************** start_function (declspecs, declarator, a
*** 12648,12656 ****
abstract_virtuals_error (decl1, TREE_TYPE (fntype));
}
- if (warn_about_return_type)
- pedwarn ("return-type defaults to `int'");
-
/* Effective C++ rule 15. See also c_expand_return. */
if (warn_ecpp
&& DECL_NAME (decl1) == ansi_opname[(int) MODIFY_EXPR]
--- 12633,12638 ----
*************** struct cp_function
*** 14106,14112 ****
{
int returns_value;
int returns_null;
- int warn_about_return_type;
int assigns_this;
int just_assigned_this;
int parms_stored;
--- 14088,14093 ----
*************** push_cp_function_context (context)
*** 14153,14159 ****
p->shadowed_labels = shadowed_labels;
p->returns_value = current_function_returns_value;
p->returns_null = current_function_returns_null;
- p->warn_about_return_type = warn_about_return_type;
p->binding_level = current_binding_level;
p->ctor_label = ctor_label;
p->dtor_label = dtor_label;
--- 14134,14139 ----
*************** pop_cp_function_context (context)
*** 14196,14202 ****
shadowed_labels = p->shadowed_labels;
current_function_returns_value = p->returns_value;
current_function_returns_null = p->returns_null;
- warn_about_return_type = p->warn_about_return_type;
current_binding_level = p->binding_level;
ctor_label = p->ctor_label;
dtor_label = p->dtor_label;
--- 14176,14181 ----
More information about the Gcc-patches
mailing list