Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 321471 - [checker] Return statement style
Summary: [checker] Return statement style
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: 8.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 8.0   Edit
Assignee: Elena Laskavaia CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-01 22:26 EDT by Marc-André Laperle CLA
Modified: 2011-05-12 16:54 EDT (History)
1 user (show)

See Also:


Attachments
Return style checker (5.59 KB, patch)
2010-08-01 22:26 EDT, Marc-André Laperle CLA
no flags Details | Diff
Return style checker, no regex + tests (8.32 KB, patch)
2010-09-16 12:55 EDT, Marc-André Laperle CLA
cdtdoug: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marc-André Laperle CLA 2010-08-01 22:26:51 EDT
Created attachment 175678 [details]
Return style checker

In some organizations, it is required to use parenthesis in the return statement when the return type is not void. This checker is off by default and is configurable using a regular expression.
Comment 1 Tomasz Wesolowski CLA 2010-08-02 05:06:06 EDT
Thanks!
Btw- I can understand this being a company's convention, but what could be the actual advantage of making the return statement look like a function?
Comment 2 Marc-André Laperle CLA 2010-08-02 11:07:29 EDT
(In reply to comment #1)
> Thanks!
> Btw- I can understand this being a company's convention, but what could be the
> actual advantage of making the return statement look like a function?

No idea. I guess some conventions are there just to make the code more consistent. This checker was useful to me and I want to contribute as much as I can :)
Comment 3 Elena Laskavaia CLA 2010-08-12 21:08:34 EDT
1) Please project a junit test for this - it is very easy to write
2) Why you using rawSignature instead of check for expression type?
Comment 4 Marc-André Laperle CLA 2010-09-10 12:14:18 EDT
(In reply to comment #3)
> 1) Please project a junit test for this - it is very easy to write
> 2) Why you using rawSignature instead of check for expression type?

I'm not sure what you mean by checking for expression type. The idea is to check the return statement against a configurable regex so I need the string of the statement. Is there a better way to do this? About the junit test, I will provide a test for the checker using the default regex.
Comment 5 Elena Laskavaia CLA 2010-09-10 12:45:22 EDT
What is the point of having customizable expression type? I don't even heard of any other possible styles for return statement.
Checking for expression type if kind of

expr instanceof ExpressionInBrakets 
(I made up the ast node name but just as example)
Comment 6 Marc-André Laperle CLA 2010-09-16 12:55:56 EDT
Created attachment 179052 [details]
Return style checker, no regex + tests

Here is the new patch that does not use a regex and includes tests.
Comment 7 Elena Laskavaia CLA 2010-09-19 21:18:04 EDT
fixed on head, thanks for the patch