Skip to content

Commit 9d75782

Browse files
authored
Merge pull request #17073 from jketema/explicit-bool
C++: Add additional test cases for `explict` and `explicit(bool)` specifiers
2 parents 9fb657c + 3e7a60c commit 9d75782

File tree

8 files changed

+119
-163
lines changed

8 files changed

+119
-163
lines changed

cpp/ql/test/library-tests/specifiers2/cpp20.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,27 @@ class TestConstexpr {
77
constexpr int member_const_constexpr() const { return 0; }
88
};
99

10+
struct TestExplict {
11+
explicit TestExplict();
12+
};
13+
14+
template<typename T>
15+
struct TestExplicitBool {
16+
explicit(sizeof(T) == 1)
17+
TestExplicitBool(const T);
18+
};
19+
20+
explicit TestExplicitBool(const double) -> TestExplicitBool<int>;
21+
22+
template<typename T>
23+
explicit(sizeof(T) == 4)
24+
TestExplicitBool(const T) -> TestExplicitBool<int>;
25+
26+
void TestExplicitBoolFun() {
27+
new TestExplicitBool<char>(0);
28+
new TestExplicitBool<int>(0);
29+
new TestExplicitBool(0.0f);
30+
new TestExplicitBool(0.0);
31+
}
32+
1033
} // namespace cpp20
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| cpp20.cpp:15:8:15:23 | TestExplicitBool<char> | file://:0:0:0:0 | char | cpp20.cpp:17:5:17:20 | TestExplicitBool | explicit, extern, public |
2+
| cpp20.cpp:15:8:15:23 | TestExplicitBool<int> | file://:0:0:0:0 | int | cpp20.cpp:17:5:17:20 | TestExplicitBool | extern, public |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import cpp
2+
3+
from MemberFunction m, ClassTemplateInstantiation c, string specifiers
4+
where
5+
c.getAMember() = m and
6+
specifiers = concat(string s | s = m.getASpecifier().getName() | s, ", ")
7+
select c, c.getATemplateArgument(), m, specifiers

cpp/ql/test/library-tests/specifiers2/specifiers2.expected

Lines changed: 63 additions & 156 deletions
Large diffs are not rendered by default.

cpp/ql/test/library-tests/specifiers2/specifiers2.ql

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ string interesting(Element e) {
1414
e instanceof VariableDeclarationEntry and result = "VariableDeclarationEntry"
1515
}
1616

17-
from Element e, string name, string specifier
17+
from Element e, string name, string specifiers
1818
where
1919
(
2020
name = e.(Declaration).getName() or
2121
name = e.(DeclarationEntry).getName() or
2222
name = e.(Type).toString()
2323
) and
24-
(
25-
specifier = e.(Declaration).getASpecifier().toString() or
26-
specifier = e.(DeclarationEntry).getASpecifier() or
27-
specifier = e.(TypedefType).getBaseType().getASpecifier().toString()
28-
)
29-
select interesting(e), e, name, specifier
24+
specifiers =
25+
concat(string s |
26+
s = e.(Declaration).getASpecifier().toString() or
27+
s = e.(DeclarationEntry).getASpecifier() or
28+
s = e.(TypedefType).getBaseType().getASpecifier().toString()
29+
|
30+
s, ", "
31+
) and
32+
specifiers != ""
33+
select interesting(e), e, name, specifiers

cpp/ql/test/library-tests/specifiers2/specifiers2d.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
| cpp20.cpp:17:28:17:28 | (unnamed parameter 0) | file://:0:0:0:0 | const T | file://:0:0:0:0 | const |
2+
| cpp20.cpp:17:28:17:28 | (unnamed parameter 0) | file://:0:0:0:0 | const char | file://:0:0:0:0 | const |
3+
| cpp20.cpp:17:28:17:28 | (unnamed parameter 0) | file://:0:0:0:0 | const int | file://:0:0:0:0 | const |
4+
| cpp20.cpp:24:24:24:24 | (unnamed parameter 0) | file://:0:0:0:0 | const T | file://:0:0:0:0 | const |
5+
| file://:0:0:0:0 | (unnamed parameter 0) | file://:0:0:0:0 | const double | file://:0:0:0:0 | const |
16
| specifiers2.c:18:21:18:23 | svi | file://:0:0:0:0 | volatile int | file://:0:0:0:0 | volatile |
27
| specifiers2.c:19:11:19:12 | ci | file://:0:0:0:0 | const int | file://:0:0:0:0 | const |
38
| specifiers2.c:21:34:21:34 | p | file://:0:0:0:0 | char *__restrict__ | file://:0:0:0:0 | restrict |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| cpp20.cpp:17:5:17:20 | TestExplicitBool | extern, public |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import cpp
2+
3+
from MemberFunction m, TemplateClass c, string specifiers
4+
where
5+
c.getAMember() = m and
6+
specifiers = concat(string s | s = m.getASpecifier().getName() | s, ", ")
7+
select m, specifiers

0 commit comments

Comments
 (0)