-
Notifications
You must be signed in to change notification settings - Fork 67
Consider "main()" with typedef'd int return type as MainFunction #647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0f832d3
Fix for issue: 646
rak3-sh 8c28f1e
Added tests and generalized fix
rak3-sh 9f88e85
Added change note for #646
rak3-sh aed7701
Delete cpp/autosar/test/rules/M0-1-10/test_main_variant.cpp
rak3-sh 26f2b31
Merge branch 'main' into rp/m0-1-10-646
rak3-sh d0807db
Corrected formatting
rak3-sh 9022a70
Merge branch 'main' into rp/m0-1-10-646
rak3-sh 0b02dc4
Merge branch 'main' into rp/m0-1-10-646
rak3-sh 0c20066
Add a non-compliant case.
rak3-sh 6a1b283
Modify comment to follow standard convention.
rak3-sh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- `M0-1-10` - `EncapsulatingFunctions.qll`: | ||
- Fixes #646. Consider typedef'd `int` return types for `main()` function as MainFunction. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| test.cpp:23:14:23:26 | uncalled_func | Function uncalled_func is never called. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rules/M0-1-10/UnusedFunction.ql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <cstdint> | ||
|
||
namespace mains { | ||
static std::int32_t var; | ||
|
||
// @brief namespace_func | ||
static void | ||
namespace_func(void) noexcept { // COMPLIANT: Called from "main" below. | ||
mains::var = -1; | ||
return; | ||
} | ||
} // namespace mains | ||
|
||
std::int32_t func2() // COMPLIANT: Called from func1 | ||
{ | ||
return mains::var + 20; | ||
} | ||
|
||
std::int32_t func1() { // COMPLIANT: Called from main | ||
return mains::var + func2(); // func2 called here. | ||
} | ||
|
||
std::int32_t uncalled_func() // NON_COMPLIANT: Not called. | ||
{ | ||
return mains::var + func1(); // func1 called here. | ||
} | ||
|
||
// @brief main | ||
// @return exit code | ||
std::int32_t main(void) { | ||
std::int32_t ret{0}; | ||
try { | ||
ret = func1(); // func1 called here. | ||
mains::var += ret; | ||
} catch (...) { | ||
mains::namespace_func(); // namespace_func called here. | ||
} | ||
return ret; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...n/test/library/codingstandards/cpp/mainlikefunctions/typedefint/MainLikeFunction.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| test.cpp:5:9:5:12 | main | |
5 changes: 5 additions & 0 deletions
5
cpp/common/test/library/codingstandards/cpp/mainlikefunctions/typedefint/MainLikeFunction.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import cpp | ||
import codingstandards.cpp.EncapsulatingFunctions | ||
|
||
from MainFunction m | ||
select m |
8 changes: 8 additions & 0 deletions
8
cpp/common/test/library/codingstandards/cpp/mainlikefunctions/typedefint/test.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
typedef signed int int32_t; | ||
|
||
// @brief main | ||
// @return exit code | ||
int32_t main(void) { | ||
int32_t ret{0}; | ||
return ret; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.