Skip to content

Commit 8321729

Browse files
jketemaCopilot
andcommitted
Add empty parameter pack regression test
Extend the unused static variable query test with a C++20 variadic parameter pack instantiated with zero and one arguments. This captures the empty-pack restrictionPack finding reported by issue #22931. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1a8dbb2 commit 8321729

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎cpp/ql/test/query-tests/Best Practices/Unused Entities/UnusedStaticVariables/UnusedStaticVariables.expected‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
| test.cpp:8:12:8:21 | staticVar6 | Static variable staticVar6 is never read. |
33
| test.cpp:10:11:10:19 | constVar8 | Static variable constVar8 is never read. |
44
| test.cpp:12:12:12:22 | staticVar10 | Static variable staticVar10 is never read. |
5+
| test.cpp:68:58:68:72 | restrictionPack | Static variable restrictionPack is never read. |

‎cpp/ql/test/query-tests/Best Practices/Unused Entities/UnusedStaticVariables/test.cpp‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// semmle-extractor-options: -std=c++17
1+
// semmle-extractor-options: -std=c++20
22
int globalVar; // GOOD (not static)
33
static int staticVar1; // GOOD (used)
44
static int staticVar2; // GOOD (used)
@@ -49,3 +49,30 @@ struct WithDestructor
4949

5050
static WithConstructor constructed; // GOOD (constructor has a side effect)
5151
static WithDestructor destructed; // GOOD (destructor has a side effect)
52+
53+
template <typename From, typename To>
54+
concept ConvertibleTo = requires(From value) { static_cast<To>(value); };
55+
56+
struct Store
57+
{
58+
using LinkAddressType = unsigned;
59+
struct LinkType
60+
{
61+
LinkAddressType restriction;
62+
};
63+
};
64+
65+
template <typename TStore>
66+
static auto All(
67+
const TStore&,
68+
ConvertibleTo<typename TStore::LinkAddressType> auto... restrictionPack) // $ SPURIOUS: Alert
69+
{
70+
typename TStore::LinkType restriction{static_cast<typename TStore::LinkAddressType>(restrictionPack)...};
71+
return restriction;
72+
}
73+
74+
int main()
75+
{
76+
Store store;
77+
return All(store).restriction + All(store, 2U).restriction;
78+
}

0 commit comments

Comments
 (0)