Skip to content

Commit 1f9a3b4

Browse files
committed
A15-5-1: Clarify message and handle implicit noexcept(true).
1 parent 089397a commit 1f9a3b4

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `A15-5-1`
2+
- Rephrase alert message for `noalert(false)` special functions to clarify that this permits exceptions.
3+
- Additional results for implicit `noexcept(true)` special functions highlighting that the specification should be made explicit.

cpp/autosar/src/rules/A15-5-1/SpecialFunctionMissingNoExceptSpecification.ql

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,25 @@ import codingstandards.cpp.exceptions.ExceptionSpecifications
2222
from SpecialFunction f, string message
2323
where
2424
not isExcluded(f, Exceptions2Package::specialFunctionMissingNoExceptSpecificationQuery()) and
25-
not isNoExceptTrue(f) and
25+
not isFDENoExceptTrue(f.getDefinition()) and
2626
not f.isCompilerGenerated() and
2727
not f.isDeleted() and
2828
not f.isDefaulted() and
2929
(
3030
isNoExceptExplicitlyFalse(f) and
31-
message = f.getQualifiedName() + " should not be noexcept(false)."
31+
message =
32+
"Special function " + f.getQualifiedName() +
33+
" has a noexcept(false) specification that permits exceptions."
3234
or
35+
isNoExceptTrue(f) and
36+
message =
37+
f.getQualifiedName() +
38+
" has an implicit noexcept(true) specification but should make that explicit."
39+
or
40+
not isNoExceptTrue(f) and
3341
not isNoExceptExplicitlyFalse(f) and
34-
message = f.getQualifiedName() + " is implicitly noexcept(false) and might throw."
42+
message =
43+
"Special function " + f.getQualifiedName() +
44+
" has an implicit noexcept(false) specification that permits exceptions."
3545
)
3646
select f, message
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
| test.cpp:5:3:5:9 | ~ClassA | ClassA::~ClassA should not be noexcept(false). |
2-
| test.cpp:9:3:9:9 | ~ClassB | ClassB::~ClassB should not be noexcept(false). |
3-
| test.cpp:38:6:38:20 | operator delete | operator delete is implicitly noexcept(false) and might throw. |
4-
| test.cpp:43:6:43:20 | operator delete | operator delete is implicitly noexcept(false) and might throw. |
5-
| test.cpp:53:11:53:19 | operator= | ClassF::operator= should not be noexcept(false). |
6-
| test.cpp:63:3:63:8 | ClassH | ClassH::ClassH should not be noexcept(false). |
7-
| test.cpp:68:6:68:9 | swap | swap is implicitly noexcept(false) and might throw. |
8-
| test.cpp:72:6:72:9 | swap | swap should not be noexcept(false). |
9-
| test.cpp:77:8:77:11 | swap | ClassI::swap is implicitly noexcept(false) and might throw. |
10-
| test.cpp:82:8:82:11 | swap | ClassJ::swap is implicitly noexcept(false) and might throw. |
11-
| test.cpp:88:6:88:6 | swap | swap is implicitly noexcept(false) and might throw. |
1+
| test.cpp:5:3:5:9 | ~ClassA | Special function ClassA::~ClassA has a noexcept(false) specification that permits exceptions. |
2+
| test.cpp:9:3:9:9 | ~ClassB | Special function ClassB::~ClassB has a noexcept(false) specification that permits exceptions. |
3+
| test.cpp:38:6:38:20 | operator delete | operator delete has an implicit noexcept(true) specification but should make that explicit. |
4+
| test.cpp:43:6:43:20 | operator delete | operator delete has an implicit noexcept(true) specification but should make that explicit. |
5+
| test.cpp:53:11:53:19 | operator= | Special function ClassF::operator= has a noexcept(false) specification that permits exceptions. |
6+
| test.cpp:63:3:63:8 | ClassH | Special function ClassH::ClassH has a noexcept(false) specification that permits exceptions. |
7+
| test.cpp:68:6:68:9 | swap | Special function swap has an implicit noexcept(false) specification that permits exceptions. |
8+
| test.cpp:72:6:72:9 | swap | Special function swap has a noexcept(false) specification that permits exceptions. |
9+
| test.cpp:77:8:77:11 | swap | Special function ClassI::swap has an implicit noexcept(false) specification that permits exceptions. |
10+
| test.cpp:82:8:82:11 | swap | Special function ClassJ::swap has an implicit noexcept(false) specification that permits exceptions. |
11+
| test.cpp:88:6:88:6 | swap | Special function swap has an implicit noexcept(false) specification that permits exceptions. |

cpp/autosar/test/rules/A15-5-1/test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "stddef.h"
2+
#include <new>
23
#include <stdexcept>
3-
44
class ClassA {
55
~ClassA() noexcept(false) { throw std::exception(); } // NON_COMPLIANT
66
};
@@ -36,12 +36,12 @@ class ClassD {
3636
};
3737

3838
void operator delete(void *ptr) { // NON_COMPLIANT
39-
// NOTE: cannot be declared noexcept(false)
39+
// NOTE: defaults to noexcept(true)
4040
throw std::exception();
4141
}
4242

4343
void operator delete(void *ptr, size_t size) { // NON_COMPLIANT
44-
// NOTE: cannot be declared noexcept(false)
44+
// NOTE: defaults to noexcept(true)
4545
throw std::exception();
4646
}
4747

0 commit comments

Comments
 (0)