[C++ PATCH, committed] Fix main return type warning (PR4494)
Kriang Lerdsuwanakij
lerdsuwa@users.sourceforge.net
Mon May 5 12:20:00 GMT 2003
Hi
This patch fixes a warning/error when the return type of main
is a typedef to int. Committed as obvious to trunk.
Tested on i686-pc-linux-gnu.
--Kriang
2003-05-05 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/4494
* decl.c (start_function): Use same_type_p to check return type
of main.
2003-05-05 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/4494
* g++.dg/warn/main.C: New test.
diff -cprN gcc-main-save/gcc/cp/decl.c gcc-main-new/gcc/cp/decl.c
*** gcc-main-save/gcc/cp/decl.c Thu May 1 16:49:56 2003
--- gcc-main-new/gcc/cp/decl.c Mon May 5 18:04:51 2003
*************** start_function (tree declspecs, tree dec
*** 13370,13377 ****
ctype = TYPE_METHOD_BASETYPE (fntype);
else if (DECL_MAIN_P (decl1))
{
! /* If this doesn't return integer_type, complain. */
! if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
{
if (pedantic || warn_return_type)
pedwarn ("return type for `main' changed to `int'");
--- 13375,13383 ----
ctype = TYPE_METHOD_BASETYPE (fntype);
else if (DECL_MAIN_P (decl1))
{
! /* If this doesn't return integer_type, or a typedef to
! integer_type, complain. */
! if (!same_type_p (TREE_TYPE (TREE_TYPE (decl1)), integer_type_node))
{
if (pedantic || warn_return_type)
pedwarn ("return type for `main' changed to `int'");
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/warn/main.C gcc-main-new/gcc/testsuite/g++.dg/warn/main.C
*** gcc-main-save/gcc/testsuite/g++.dg/warn/main.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/warn/main.C Mon May 5 14:29:53 2003
***************
*** 0 ****
--- 1,11 ----
+ // { dg-do compile }
+
+ // Origin: Donald W. Gillies <dgillies@graviton.com>
+
+ // PR c++/4494: Incorrect diagnostics about return type of main.
+
+ typedef int int_t;
+
+ int_t main() {
+
+ }
More information about the Gcc-patches
mailing list