@@ -19,6 +19,36 @@ import codingstandards.cpp.autosar
19
19
import codingstandards.cpp.exceptions.ExceptionSpecifications
20
20
import codingstandards.cpp.exceptions.ExceptionFlow
21
21
22
+ // These functions have a noexcept specification that could not be resolved
23
+ // to noexcept(true). So either, they are noexcept(false) functions which
24
+ // means, they can throw an exception OR they have an expression which
25
+ // could not be resolved to "true" or "false". Even in this case, lets
26
+ // be more conservative and assume they may thrown an exception.
27
+ class FunctionWithUnknownNoExcept extends Function {
28
+ FunctionWithUnknownNoExcept ( ) {
29
+ // Exists a noexcept specification but not noexcept(true)
30
+ exists ( this .getADeclarationEntry ( ) .getNoExceptExpr ( ) ) and
31
+ not isNoExceptTrue ( this )
32
+ }
33
+ }
34
+
35
+ // This predicate checks if a function can call to other functions
36
+ // that may have a noexcept specification which cannot be resolved to
37
+ // noexcept(true).
38
+ predicate mayCallThrowingFunctions ( Function f ) {
39
+ // Exists a call in this function
40
+ exists ( Call fc |
41
+ fc .getEnclosingFunction ( ) = f and
42
+ (
43
+ // Either this call is to a function with an unknown noexcept OR
44
+ fc .getTarget ( ) instanceof FunctionWithUnknownNoExcept
45
+ or
46
+ // That function can further have calls to unknown noexcept functions.
47
+ mayCallThrowingFunctions ( fc .getTarget ( ) )
48
+ )
49
+ )
50
+ }
51
+
22
52
from Function f
23
53
where
24
54
not isExcluded ( f , Exceptions1Package:: missingNoExceptQuery ( ) ) and
28
58
not isNoExceptTrue ( f ) and
29
59
// Not explicitly marked noexcept(false)
30
60
not isNoExceptExplicitlyFalse ( f ) and
61
+ // Not having a noexcept specification that
62
+ // could not be computed as true or false above.
63
+ not exists ( f .getADeclarationEntry ( ) .getNoExceptExpr ( ) ) and
64
+ // Not calling function(s) which have a noexcept specification that
65
+ // could not be computed as true.
66
+ not mayCallThrowingFunctions ( f ) and
31
67
// Not compiler generated
32
68
not f .isCompilerGenerated ( ) and
33
69
// The function is defined in this database
0 commit comments