Skip to content

Commit

Permalink
Merge pull request #17073 from jketema/explicit-bool
Browse files Browse the repository at this point in the history
C++: Add additional test cases for `explict` and `explicit(bool)` specifiers
  • Loading branch information
jketema committed Jul 25, 2024
2 parents 9fb657c + 3e7a60c commit 9d75782
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 163 deletions.
23 changes: 23 additions & 0 deletions cpp/ql/test/library-tests/specifiers2/cpp20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,27 @@ class TestConstexpr {
constexpr int member_const_constexpr() const { return 0; }
};

struct TestExplict {
explicit TestExplict();
};

template<typename T>
struct TestExplicitBool {
explicit(sizeof(T) == 1)
TestExplicitBool(const T);
};

explicit TestExplicitBool(const double) -> TestExplicitBool<int>;

template<typename T>
explicit(sizeof(T) == 4)
TestExplicitBool(const T) -> TestExplicitBool<int>;

void TestExplicitBoolFun() {
new TestExplicitBool<char>(0);
new TestExplicitBool<int>(0);
new TestExplicitBool(0.0f);
new TestExplicitBool(0.0);
}

} // namespace cpp20
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| cpp20.cpp:15:8:15:23 | TestExplicitBool<char> | file://:0:0:0:0 | char | cpp20.cpp:17:5:17:20 | TestExplicitBool | explicit, extern, public |
| cpp20.cpp:15:8:15:23 | TestExplicitBool<int> | file://:0:0:0:0 | int | cpp20.cpp:17:5:17:20 | TestExplicitBool | extern, public |
7 changes: 7 additions & 0 deletions cpp/ql/test/library-tests/specifiers2/inst_func_specifiers.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import cpp

from MemberFunction m, ClassTemplateInstantiation c, string specifiers
where
c.getAMember() = m and
specifiers = concat(string s | s = m.getASpecifier().getName() | s, ", ")
select c, c.getATemplateArgument(), m, specifiers
219 changes: 63 additions & 156 deletions cpp/ql/test/library-tests/specifiers2/specifiers2.expected

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions cpp/ql/test/library-tests/specifiers2/specifiers2.ql
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ string interesting(Element e) {
e instanceof VariableDeclarationEntry and result = "VariableDeclarationEntry"
}

from Element e, string name, string specifier
from Element e, string name, string specifiers
where
(
name = e.(Declaration).getName() or
name = e.(DeclarationEntry).getName() or
name = e.(Type).toString()
) and
(
specifier = e.(Declaration).getASpecifier().toString() or
specifier = e.(DeclarationEntry).getASpecifier() or
specifier = e.(TypedefType).getBaseType().getASpecifier().toString()
)
select interesting(e), e, name, specifier
specifiers =
concat(string s |
s = e.(Declaration).getASpecifier().toString() or
s = e.(DeclarationEntry).getASpecifier() or
s = e.(TypedefType).getBaseType().getASpecifier().toString()
|
s, ", "
) and
specifiers != ""
select interesting(e), e, name, specifiers
5 changes: 5 additions & 0 deletions cpp/ql/test/library-tests/specifiers2/specifiers2d.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
| cpp20.cpp:17:28:17:28 | (unnamed parameter 0) | file://:0:0:0:0 | const T | file://:0:0:0:0 | const |
| cpp20.cpp:17:28:17:28 | (unnamed parameter 0) | file://:0:0:0:0 | const char | file://:0:0:0:0 | const |
| cpp20.cpp:17:28:17:28 | (unnamed parameter 0) | file://:0:0:0:0 | const int | file://:0:0:0:0 | const |
| cpp20.cpp:24:24:24:24 | (unnamed parameter 0) | file://:0:0:0:0 | const T | file://:0:0:0:0 | const |
| file://:0:0:0:0 | (unnamed parameter 0) | file://:0:0:0:0 | const double | file://:0:0:0:0 | const |
| specifiers2.c:18:21:18:23 | svi | file://:0:0:0:0 | volatile int | file://:0:0:0:0 | volatile |
| specifiers2.c:19:11:19:12 | ci | file://:0:0:0:0 | const int | file://:0:0:0:0 | const |
| specifiers2.c:21:34:21:34 | p | file://:0:0:0:0 | char *__restrict__ | file://:0:0:0:0 | restrict |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| cpp20.cpp:17:5:17:20 | TestExplicitBool | extern, public |
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import cpp

from MemberFunction m, TemplateClass c, string specifiers
where
c.getAMember() = m and
specifiers = concat(string s | s = m.getASpecifier().getName() | s, ", ")
select m, specifiers

0 comments on commit 9d75782

Please sign in to comment.