| Summary: | Parser gives warning if main does not return anything | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Tools] CDT | Reporter: | Nathan Ridge <zeratul976> | ||||
| Component: | cdt-codan | Assignee: | 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: |
|
||||||
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.
Personally I think people should just writer a better code by adding a return in main. Fixed anyway in cdt8 branch and head I think many things too, but you can't satisfy everyone's opinions at the same time. That is why we have a standard :) |
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.