Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 332283

Summary: Parser gives warning if main does not return anything
Product: [Tools] CDT Reporter: Nathan Ridge <zeratul976>
Component: cdt-codanAssignee: Elena Laskavaia <elaskavaia.cdt>
Status: RESOLVED FIXED QA Contact: Elena Laskavaia <elaskavaia.cdt>
Severity: normal    
Priority: P3 CC: cdtdoug, malaperle, stg.open, yevshif
Version: 8.0   
Target Milestone: 8.0.1   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Fix elaskavaia.cdt: iplog+

Description Nathan Ridge CLA 2010-12-10 03:55:19 EST
For this code:

int main()
{
}

The parser gives the warning:

No return, in function returning non-void

The parser should make an exception for main(), as the standard explicitly allows main to return nothing (section 3.6.1/5), in which case the effect is the same as returning 0.
Comment 1 Stefan Gh CLA 2011-01-18 12:39:24 EST
Created attachment 187023 [details]
Fix

Added the method isMain() to check if the function is main or not. If it is, a missing return value is not treated as a problem.

Also added a junit test method testMainFunction() which tests a main function with no return value; it is expected to return no errors.
Comment 2 Elena Laskavaia CLA 2011-06-27 22:08:18 EDT
Personally I think people should just writer a better code by adding a return in main. Fixed anyway in cdt8 branch and head
Comment 3 Nathan Ridge CLA 2011-06-27 22:16:39 EDT
I think many things too, but you can't satisfy everyone's opinions at the same time. That is why we have a standard :)