Bug 6321 - no warning for bad main function declaration
Summary: no warning for bad main function declaration
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.0.2
: P3 enhancement
Target Milestone: ---
Assignee: Dirk Mueller
URL:
Keywords: diagnostic
: 11435 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-04-16 05:06 UTC by benedictbrown
Modified: 2006-10-30 23:22 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-12-11 21:57:31


Attachments
bert.ii (280 bytes, text/x-c++)
2003-05-21 15:16 UTC, benedictbrown
Details

Note You need to log in before you can comment on or make changes to this bug.
Description benedictbrown 2002-04-16 05:06:00 UTC
No warning is given when the main function arguments are wrong (not argc, argv), even when -Wall is set.  The program simply seg faults when it's run.  A warning _is_ given that the return type is incorrect.

The output with -v is listed below (gcc):
Reading specs from /opt/at/gcc/3.0.2/lib/gcc-lib/i686-pc-linux-gnu/3.0.2/specs
Configured with: ../gcc-3.0.2/configure --prefix=/opt/at/gcc/3.0.2 --with-local-prefix=/opt/at/gcc/3.0.2 --with-gnu-as --with-as=/opt/at/gcc/3.0.2/bin/as --with-gnu-ld --with-ld=/opt/at/gcc/3.0.2/bin/ld --enable-cpp --enable-languages=c++ --disable-shared --disable-nls --host=i686-pc-linux-gnu
Thread model: single
gcc version 3.0.2
 /opt/at/gcc/3.0.2/lib/gcc-lib/i686-pc-linux-gnu/3.0.2/cpp0 -lang-c++ -D__GNUG__=3 -D__GXX_DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -v -I/edc/wa/benedict/g1_es1/csfg/ixl_gnu-assert-dbg/Tree/include -I. -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=2 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -Wall -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ bert.cxx bert.ii
GNU CPP version 3.0.2 (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "/opt/at/gcc/3.0.2/i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /edc/wa/benedict/g1_es1/csfg/ixl_gnu-assert-dbg/Tree/include
 .
 /opt/at/gcc/3.0.2/include/g++-v3
 /opt/at/gcc/3.0.2/include/g++-v3/i686-pc-linux-gnu
 /opt/at/gcc/3.0.2/include/g++-v3/backward
 /opt/at/gcc/3.0.2/include
 /opt/at/gcc/3.0.2/lib/gcc-lib/i686-pc-linux-gnu/3.0.2/include
 /usr/include
End of search list.
 /opt/at/gcc/3.0.2/lib/gcc-lib/i686-pc-linux-gnu/3.0.2/cc1plus -fpreprocessed bert.ii -quiet -dumpbase bert.cxx -g -ggdb -gstabs+ -Wall -version -o bert.s
GNU CPP version 3.0.2 (cpplib) (i386 Linux/ELF)
GNU C++ version 3.0.2 (i686-pc-linux-gnu)
	compiled by GNU C version 3.0.2.
bert.cxx:45: `main' must return `int'
bert.cxx:45: return type for `main' changed to `int'

Release:
unknown

Environment:
RH Linux 7.2 (full install).
Tested on both gcc 2.95.3 and gcc 3.0.2

How-To-Repeat:
just compile included source
Comment 1 Nathan Sidwell 2002-09-15 05:35:19 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: probably a sensible warning. main's parms are implementation
    defined
Comment 2 Andrew Pinski 2003-07-04 17:05:15 UTC
*** Bug 11435 has been marked as a duplicate of this bug. ***
Comment 3 Andrew Pinski 2005-01-13 01:08:28 UTC
Note the C front-end warns:
t.cc:2: warning: second argument of 'main' should be 'char **'
t.cc:2: warning: third argument of 'main' should probably be 'char **'
t.cc:2: warning: 'main' takes only zero or two arguments
Comment 4 Dirk Mueller 2006-10-28 23:45:01 UTC
testing patch
Comment 5 Dirk Mueller 2006-10-30 23:15:52 UTC
Subject: Bug 6321

Author: mueller
Date: Mon Oct 30 23:15:42 2006
New Revision: 118206

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118206
Log:
2006-10-30  Dirk Mueller  <dmueller@suse.de>

        PR c++/6321
        * cp/decl.c (grokfndecl): Use check_main_parameter_types.

        * c-common.h (strict_aliasing_warning): Fix whitespace.
        * c-decl (start_function): Move code for main decl warning ..
        * c-common.c (check_main_parameter_types): .. here.
        * c-common.h (check_main_parameter_types): Declare.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/c-common.h
    trunk/gcc/c-decl.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c

Comment 6 Dirk Mueller 2006-10-30 23:22:16 UTC
Fixed for 4.3.0