X Tutup
Skip to content

Commit fe37604

Browse files
First few queries implemented
1 parent 7f9ed57 commit fe37604

File tree

11 files changed

+148
-18
lines changed

11 files changed

+148
-18
lines changed

cpp/common/test/includes/standard-library/functional.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ template <class T> struct equal_to {
8585
typedef bool result_type;
8686
};
8787

88+
template <class Predicate> class unary_negate {
89+
public:
90+
unary_negate() = default;
91+
explicit unary_negate(const Predicate &pred);
92+
bool operator()(const typename Predicate::argument_type &x) const;
93+
};
94+
95+
template <class Predicate> class binary_negate {
96+
public:
97+
binary_negate() = default;
98+
explicit binary_negate(const Predicate &pred);
99+
bool operator()(const typename Predicate::first_argument_type &x,
100+
const typename Predicate::second_argument_type &y) const;
101+
};
102+
88103
template <class> class function;
89104
template <class R, class... Args> class function<R(Args...)> {
90105
public:

cpp/common/test/includes/standard-library/memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ template <typename T> class shared_ptr : public __shared_ptr<T> {
103103
~shared_ptr() {}
104104
T &operator*() const noexcept;
105105
T *operator->() const noexcept;
106+
bool unique() const noexcept;
106107

107108
shared_ptr<T> &operator=(const shared_ptr &) {}
108109
shared_ptr<T> &operator=(shared_ptr &&) { return *this; }

cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedCHeaders.ql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import cpp
1717
import codingstandards.cpp.misra
1818

19-
from
19+
from Include include, string includeText
2020
where
21-
not isExcluded(x, Toolchain3Package::useOfDeprecatedCHeadersQuery()) and
22-
select
21+
not isExcluded(include, Toolchain3Package::useOfDeprecatedCHeadersQuery()) and
22+
includeText = include.getIncludeText() and
23+
includeText = "<c" + ["complex", "stdalign", "stdbool", "tgmath"] + ">"
24+
select include, "Inclusion of deprecated C header '" + includeText + "'."

cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedIsLiteralTypeTraits.ql

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,44 @@
1717
import cpp
1818
import codingstandards.cpp.misra
1919

20-
from
20+
class IsLiteralTypeTemplate extends TemplateClass {
21+
IsLiteralTypeTemplate() { this.hasQualifiedName("std", "is_literal_type") }
22+
}
23+
24+
class IsLiteralTypeVariable extends TemplateVariable {
25+
IsLiteralTypeVariable() { this.hasQualifiedName("std", "is_literal_type") }
26+
}
27+
28+
from Element usage, string type, string useKind
2129
where
22-
not isExcluded(x, Toolchain3Package::useOfDeprecatedIsLiteralTypeTraitsQuery()) and
23-
select
30+
not isExcluded(usage, Toolchain3Package::useOfDeprecatedIsLiteralTypeTraitsQuery()) and
31+
(
32+
exists(ClassTemplateInstantiation c |
33+
c.getTemplate() instanceof IsLiteralTypeTemplate and
34+
usage.(TypeMention).getMentionedType() = c and
35+
type = "std::is_literal_type" and
36+
useKind = "instantiation"
37+
)
38+
or
39+
exists(VariableTemplateInstantiation v |
40+
v.getTemplate() instanceof IsLiteralTypeVariable and
41+
usage.(VariableAccess).getTarget() = v and
42+
type = "std::is_literal_type" and
43+
useKind = "instantiation"
44+
)
45+
or
46+
exists(ClassTemplateSpecialization cti |
47+
cti.getPrimaryTemplate() instanceof IsLiteralTypeTemplate and
48+
usage.(TypeMention).getMentionedType() = cti and
49+
type = "std::is_literal_type" and
50+
useKind = "specialization"
51+
)
52+
or
53+
exists(VariableTemplateSpecialization vts |
54+
vts.getPrimaryTemplate() instanceof IsLiteralTypeVariable and
55+
usage.(VariableAccess).getTarget() = vts and
56+
type = "std::is_literal_type" and
57+
useKind = "specialization"
58+
)
59+
)
60+
select usage, "Use of deprecated type trait '" + type + "' through " + useKind + "."

cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedSharedPtrUnique.ql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
import cpp
1818
import codingstandards.cpp.misra
1919

20-
from
20+
from MemberFunction mf, FunctionCall fc
2121
where
22-
not isExcluded(x, Toolchain3Package::useOfDeprecatedSharedPtrUniqueQuery()) and
23-
select
22+
not isExcluded(fc, Toolchain3Package::useOfDeprecatedSharedPtrUniqueQuery()) and
23+
mf = fc.getTarget() and
24+
mf.hasName("unique") and
25+
mf.getDeclaringType().(ClassTemplateInstantiation).hasQualifiedName("std", "shared_ptr")
26+
select fc, "Call to deprecated member function 'std::shared_ptr::unique'."

cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedUnaryOrBinaryNegate.ql

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@
1717
import cpp
1818
import codingstandards.cpp.misra
1919

20-
from
20+
predicate isUnaryOrBinaryNegate(ClassTemplateInstantiation c) {
21+
c.hasQualifiedName("std", ["unary_negate", "binary_negate"])
22+
}
23+
24+
predicate isUsingUnaryOrBinaryNegate(ClassTemplateInstantiation c) {
25+
isUnaryOrBinaryNegate(c) or
26+
isUsingUnaryOrBinaryNegate(c.getTemplateArgument(_))
27+
}
28+
29+
from Variable v, ClassTemplateInstantiation c
2130
where
22-
not isExcluded(x, Toolchain3Package::useOfDeprecatedUnaryOrBinaryNegateQuery()) and
23-
select
31+
not isExcluded(v, Toolchain3Package::useOfDeprecatedUnaryOrBinaryNegateQuery()) and
32+
v.getUnderlyingType() = c and
33+
not v.isFromTemplateInstantiation(_) and
34+
isUsingUnaryOrBinaryNegate(c)
35+
select v, "Use of deprecated type 'std::" + c.getSimpleName() + "'."

cpp/misra/src/rules/RULE-4-1-2/UseOfUncaughtException.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
import cpp
1818
import codingstandards.cpp.misra
1919

20-
from
20+
from FunctionCall fc
2121
where
22-
not isExcluded(x, Toolchain3Package::useOfUncaughtExceptionQuery()) and
23-
select
22+
not isExcluded(fc, Toolchain3Package::useOfUncaughtExceptionQuery()) and
23+
fc.getTarget().hasQualifiedName("std", "uncaught_exception")
24+
select fc, "Call to deprecated function 'std::uncaught_exception'."
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
No expected results have yet been specified
1+
| test.cpp:36:6:36:11 | call to unique | Call to deprecated member function 'std::shared_ptr::unique'. |
2+
| test.cpp:38:12:38:17 | call to unique | Call to deprecated member function 'std::shared_ptr::unique'. |
3+
| test.cpp:39:15:39:20 | call to unique | Call to deprecated member function 'std::shared_ptr::unique'. |
4+
| test.cpp:43:6:43:11 | call to unique | Call to deprecated member function 'std::shared_ptr::unique'. |
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
No expected results have yet been specified
1+
| test.cpp:25:27:25:28 | g1 | Use of deprecated type 'std::unary_negate'. |
2+
| test.cpp:26:30:26:31 | g2 | Use of deprecated type 'std::binary_negate'. |
3+
| test.cpp:29:29:29:30 | l1 | Use of deprecated type 'std::unary_negate'. |
4+
| test.cpp:30:32:30:33 | l2 | Use of deprecated type 'std::binary_negate'. |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
No expected results have yet been specified
1+
| test.cpp:12:20:12:42 | call to uncaught_exception | Call to deprecated function 'std::uncaught_exception'. |

0 commit comments

Comments
 (0)
X Tutup