Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 332283 - Parser gives warning if main does not return anything
Summary: Parser gives warning if main does not return anything
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: 8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 8.0.1   Edit
Assignee: Elena Laskavaia CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-10 03:55 EST by Nathan Ridge CLA
Modified: 2011-06-27 22:16 EDT (History)
4 users (show)

See Also:


Attachments
Fix (2.33 KB, patch)
2011-01-18 12:39 EST, Stefan Gh CLA
elaskavaia.cdt: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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 :)