From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6562 invoked by alias); 17 May 2007 15:46:37 -0000 Received: (qmail 6493 invoked by uid 48); 17 May 2007 15:46:18 -0000 Date: Thu, 17 May 2007 15:46:00 -0000 Subject: [Bug c/31977] New: can return OK from "int main()" without a return statement by using a goto before the return X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "bmcfadden at cdp dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-05/txt/msg01325.txt.bz2 I'm using gcc 3.4.5, and I was looking into a weird condition. The following program compiles OK: #include int alloc() { return 0; } int main(int argc, char* argv[]) { printf("Testing!\n"); if(alloc() == 0)goto Radhe; return 0; Radhe: printf("Hello\n"); } The result is a program which prints "Testing", then "Hello", and then exits. I and a few other people expect that the compiler would generate an error during compile, because main should return an int, and not all code paths have a return statement; however, both gcc and msvc are compiling this OK. added note: this bug was recently discussed on the NTDEV mailing list. -- Summary: can return OK from "int main()" without a return statement by using a goto before the return Product: gcc Version: 3.4.5 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bmcfadden at cdp dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31977