Skip to content

Commit a65a8b8

Browse files
committed
Consider temporary object expression to determine type usage
1 parent 5a54165 commit a65a8b8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

cpp/common/src/codingstandards/cpp/TypeUses.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ private Locatable getATypeUse_i(Type type) {
132132
result = nq and
133133
type = nq.getQualifyingElement()
134134
)
135+
// Temporary object creation of type `type`
136+
or
137+
exists(TemporaryObjectExpr toe | result = toe | type = toe.getType())
135138
)
136139
or
137140
// Recursive case - used by a used type

cpp/common/test/rules/unusedtypedeclarations/test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,14 @@ template <typename T> using Z = Y<T>; // COMPLIANT - used below
111111
template <typename T> using AA = Y<T>; // NON_COMPLIANT - never instantiated
112112

113113
void test_alias_template() { Z<int> v; }
114+
115+
void test_temporary_object_creation() {
116+
auto l1 = [](const auto &p1) noexcept {
117+
class C1 { // COMPLIANT - used in temporary object construction
118+
public:
119+
constexpr static const char *m1() noexcept { return "foo"; }
120+
};
121+
122+
return C1{p1};
123+
};
124+
}

0 commit comments

Comments
 (0)