Skip to content

Commit

Permalink
Merge pull request #416 from github/lcartey/a15-4-4-fix-noexcept
Browse files Browse the repository at this point in the history
`A15-4-4`: Ignore results on uninstantiated templates
  • Loading branch information
Nikita Kraiouchkine authored Dec 6, 2023
2 parents d74222a + cba155c commit 52a4275
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions change_notes/2023-10-26-a15-4-4-noexcept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `A15-4-4`: remove false positives reported on uninsantiated templates.
6 changes: 4 additions & 2 deletions cpp/autosar/src/rules/A15-4-4/MissingNoExcept.ql
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ where
// The function is defined in this database
f.hasDefinition() and
// This function is not an overriden call operator of a lambda expression
not exists(LambdaExpression lambda | lambda.getLambdaFunction() = f)
select f, "Function " + f.getName() + " could be declared noexcept(true)."
not exists(LambdaExpression lambda | lambda.getLambdaFunction() = f) and
// Exclude results from uinstantiated templates
not f.isFromUninstantiatedTemplate(_)
select f, "Function " + f.getQualifiedName() + " could be declared noexcept(true)."
13 changes: 13 additions & 0 deletions cpp/autosar/test/rules/A15-4-4/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,17 @@ class A {
void lambda_example() noexcept {
auto with_capture = [=]() {};
auto empty_capture = []() {};
}

#include <utility>
template <typename TypeA, typename TypeB>
void swap_wrapper(TypeA lhs,
TypeB rhs) noexcept(noexcept(std::swap(*lhs, *rhs))) {
std::swap(*lhs, *rhs);
}

void test_swap_wrapper() noexcept {
int a = 0;
int b = 1;
swap_wrapper(&a, &b);
}

0 comments on commit 52a4275

Please sign in to comment.