-
Notifications
You must be signed in to change notification settings - Fork 67
Fix false positives of M0-1-10 (#711) #725
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
17 commits
Select commit
Hold shift + click to select a range
52a02f3
Fix #711
rak3-sh d7e4d6c
Merge branch 'main' into rp/m0-1-10-711
rak3-sh 7bf12c4
Fix new query addition
rak3-sh a48c7cc
Simplify GoogleTestFunction
rak3-sh bd83048
Reuse SpecialMemberFunction class
rak3-sh 2abec7e
Merge branch 'main' into rp/m0-1-10-711
lcartey 97bf53a
Correct exclusion
rak3-sh db37944
Merge branch 'main' into rp/m0-1-10-711
rak3-sh c5cdf0e
Add GoogleTest stub and test cases
rak3-sh 0f3bd45
Merge branch 'main' into rp/m0-1-10-711
rak3-sh 2357494
Dont report SpecialMemberFunction
rak3-sh 2ffccb0
Fix isExcluded function parameter in query
lcartey 4b1429b
SpecialMemberFunction from GoogleTest as entry pts
rak3-sh 823d04c
Merge branch 'main' into rp/m0-1-10-711
rak3-sh f2cf20e
Merge branch 'main' into rp/m0-1-10-711
rak3-sh 3bedebb
Minor improvement
rak3-sh a2943f6
Merge branch 'main' into rp/m0-1-10-711
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` - `UnusedFunction.ql`: | ||
- Fixes #711. Excludes constexpr functions, considers functions from GoogleTest as an EntryPoint and does not consider special member functions. Another query called UnusedSplMemberFunction.ql is created that reports unused special member functions. This is done so as to enable deviations to be applied to this case. |
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
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,31 @@ | ||
/** | ||
* @id cpp/autosar/unused-spl-member-function | ||
* @name M0-1-10: Every defined function should be called at least once | ||
* @description Uncalled functions complicate the program and can indicate a possible mistake on the | ||
* part of the programmer. | ||
* @kind problem | ||
* @precision medium | ||
* @problem.severity warning | ||
* @tags external/autosar/id/m0-1-10 | ||
* readability | ||
* maintainability | ||
* external/autosar/allocated-target/implementation | ||
* external/autosar/enforcement/automated | ||
* external/autosar/obligation/advisory | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.cpp.autosar | ||
import codingstandards.cpp.deadcode.UnusedFunctions | ||
|
||
from UnusedFunctions::UnusedSplMemberFunction unusedSplMemFunction, string name | ||
where | ||
not isExcluded(unusedSplMemFunction, DeadCodePackage::unusedFunctionQuery()) and | ||
( | ||
if exists(unusedSplMemFunction.getQualifiedName()) | ||
then name = unusedSplMemFunction.getQualifiedName() | ||
else name = unusedSplMemFunction.getName() | ||
) and | ||
not unusedSplMemFunction.isDeleted() | ||
select unusedSplMemFunction, | ||
"Special member function " + name + " is " + unusedSplMemFunction.getDeadCodeType() |
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
2 changes: 2 additions & 0 deletions
2
cpp/autosar/test/rules/M0-1-10/UnusedSplMemberFunction.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,2 @@ | ||
| test.cpp:71:5:71:16 | ANestedClass | Special member function ANestedClass is never called. | | ||
| test.cpp:82:5:82:22 | AnotherNestedClass | Special member function AnotherNestedClass is never called from a main function or entry point. | |
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/UnusedSplMemberFunction.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
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,4 @@ | ||
template <class T> | ||
constexpr T aCalledFuncInHeader(T value) noexcept { // COMPLIANT | ||
return static_cast<T>(value); | ||
} |
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
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
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
29 changes: 29 additions & 0 deletions
29
cpp/common/test/includes/custom-library/gtest/gtest-internal.h
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,29 @@ | ||
#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ | ||
#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ | ||
|
||
#define GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ | ||
test_suite_name##_##test_name##_Test | ||
|
||
#define GTEST_TEST_(test_suite_name, test_name, parent_class) \ | ||
class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ | ||
: public parent_class { \ | ||
public: \ | ||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() = default; \ | ||
~GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() override = default; \ | ||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ | ||
(const GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) &) = delete; \ | ||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) & operator=( \ | ||
const GTEST_TEST_CLASS_NAME_(test_suite_name, \ | ||
test_name) &) = delete; /* NOLINT */ \ | ||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ | ||
(GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) &&) noexcept = delete; \ | ||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) & operator=( \ | ||
GTEST_TEST_CLASS_NAME_(test_suite_name, \ | ||
test_name) &&) noexcept = delete; /* NOLINT */ \ | ||
\ | ||
private: \ | ||
void TestBody() override; \ | ||
}; \ | ||
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody() \ | ||
|
||
#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ |
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,28 @@ | ||
#ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_H_ | ||
#define GOOGLETEST_INCLUDE_GTEST_GTEST_H_ | ||
|
||
#include "gtest/gtest-internal.h" | ||
|
||
namespace testing { | ||
|
||
class Test | ||
{ | ||
public: | ||
virtual ~Test(); | ||
protected: | ||
// Creates a Test object. | ||
Test(); | ||
private: | ||
virtual void TestBody() = 0; | ||
Test(const Test&) = delete; | ||
Test& operator=(const Test&) = delete; | ||
}; | ||
|
||
#define GTEST_TEST(test_suite_name, test_name) \ | ||
GTEST_TEST_(test_suite_name, test_name, ::testing::Test) | ||
|
||
#define TEST(test_suite_name, test_name) GTEST_TEST(test_suite_name, test_name) | ||
|
||
} // namespace testing | ||
|
||
#endif // GOOGLETEST_INCLUDE_GTEST_GTEST_H_ |
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 |
---|---|---|
@@ -1 +1 @@ | ||
semmle-extractor-options:--clang -std=c++14 -nostdinc++ -I../../../../common/test/includes/standard-library -I../../../../common/test/includes/custom-library | ||
semmle-extractor-options:--clang -std=c++14 -nostdinc++ -I../../../../common/test/includes/standard-library -I../../../../common/test/includes/custom-library |
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
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.