Skip to content

Commit 5f635ac

Browse files
authored
Merge pull request github#3768 from geoffw0/copymove
C++: Clean up ConversionConstructor.
2 parents 9e78341 + 9f5c37c commit 5f635ac

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

cpp/ql/src/semmle/code/cpp/MemberFunction.qll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ abstract class ImplicitConversionFunction extends MemberFunction {
214214
}
215215

216216
/**
217+
* DEPRECATED: as of C++11 this class does not correspond perfectly with the
218+
* language definition of a converting constructor.
219+
*
217220
* A C++ constructor that also defines an implicit conversion. For example the
218221
* function `MyClass` in the following code is a `ConversionConstructor`:
219222
* ```
@@ -225,15 +228,16 @@ abstract class ImplicitConversionFunction extends MemberFunction {
225228
* };
226229
* ```
227230
*/
228-
class ConversionConstructor extends Constructor, ImplicitConversionFunction {
231+
deprecated class ConversionConstructor extends Constructor, ImplicitConversionFunction {
229232
ConversionConstructor() {
230233
strictcount(Parameter p | p = getAParameter() and not p.hasInitializer()) = 1 and
231-
not hasSpecifier("explicit") and
232-
not this instanceof CopyConstructor
234+
not hasSpecifier("explicit")
233235
}
234236

235237
override string getAPrimaryQlClass() {
236-
not this instanceof MoveConstructor and result = "ConversionConstructor"
238+
not this instanceof CopyConstructor and
239+
not this instanceof MoveConstructor and
240+
result = "ConversionConstructor"
237241
}
238242

239243
/** Gets the type this `ConversionConstructor` takes as input. */

cpp/ql/src/semmle/code/cpp/models/implementations/MemberFunction.qll

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ import semmle.code.cpp.models.interfaces.DataFlow
77
import semmle.code.cpp.models.interfaces.Taint
88

99
/**
10-
* Model for C++ conversion constructors.
10+
* Model for C++ conversion constructors. As of C++11 this does not correspond
11+
* perfectly with the language definition of a converting constructor, however,
12+
* it does correspond with the constructors we are confident taint should flow
13+
* through.
1114
*/
12-
class ConversionConstructorModel extends ConversionConstructor, TaintFunction {
15+
class ConversionConstructorModel extends Constructor, TaintFunction {
16+
ConversionConstructorModel() {
17+
strictcount(Parameter p | p = getAParameter() and not p.hasInitializer()) = 1 and
18+
not hasSpecifier("explicit")
19+
}
20+
1321
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
1422
// taint flow from the first constructor argument to the returned object
1523
input.isParameter(0) and

cpp/ql/test/library-tests/functions/functions/Functions2.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
| functions.cpp:23:7:23:11 | Table | Class | functions.cpp:30:8:30:13 | insert | |
2121
| functions.cpp:33:7:33:13 | MyClass | Class | functions.cpp:33:7:33:7 | operator= | |
2222
| functions.cpp:33:7:33:13 | MyClass | Class | functions.cpp:36:2:36:8 | MyClass | Constructor, NoArgConstructor, getAConstructor() |
23-
| functions.cpp:33:7:33:13 | MyClass | Class | functions.cpp:37:2:37:8 | MyClass | Constructor, ConversionConstructor, getAConstructor() |
23+
| functions.cpp:33:7:33:13 | MyClass | Class | functions.cpp:37:2:37:8 | MyClass | Constructor, getAConstructor() |
2424
| functions.cpp:33:7:33:13 | MyClass | Class | functions.cpp:38:2:38:8 | MyClass | Constructor, CopyConstructor, getAConstructor() |
25-
| functions.cpp:33:7:33:13 | MyClass | Class | functions.cpp:39:2:39:8 | MyClass | Constructor, ConversionConstructor, MoveConstructor, getAConstructor() |
25+
| functions.cpp:33:7:33:13 | MyClass | Class | functions.cpp:39:2:39:8 | MyClass | Constructor, MoveConstructor, getAConstructor() |
2626
| functions.cpp:33:7:33:13 | MyClass | Class | functions.cpp:40:2:40:13 | operator int | ConversionOperator |

cpp/ql/test/library-tests/functions/functions/Functions2.ql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ string describe(Class c, MemberFunction f) {
1919
f instanceof Destructor and
2020
result = "Destructor"
2121
or
22-
f instanceof ConversionConstructor and
23-
result = "ConversionConstructor"
24-
or
2522
f instanceof CopyConstructor and
2623
result = "CopyConstructor"
2724
or

0 commit comments

Comments
 (0)