Skip to content

Commit 56caa5d

Browse files
committed
C++: fix hasImplicitCopyConstructor for templates
Fixes some cases in instantiations of templates with manually written copy constructors or copy assignment operators where hasImplicitCopyConstructor would incorrectly hold
1 parent 61c315d commit 56caa5d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

cpp/ql/lib/semmle/code/cpp/Class.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,16 @@ class Class extends UserType {
286286
not this.implicitCopyConstructorDeleted() and
287287
forall(CopyConstructor cc | cc = this.getAMemberFunction() |
288288
cc.isCompilerGenerated() and not cc.isDeleted()
289+
) and
290+
(
291+
not this instanceof ClassTemplateInstantiation
292+
or
293+
this.(ClassTemplateInstantiation).getTemplate().hasImplicitCopyConstructor()
294+
) and
295+
(
296+
not this instanceof PartialClassTemplateSpecialization
297+
or
298+
this.(PartialClassTemplateSpecialization).getPrimaryTemplate().hasImplicitCopyConstructor()
289299
)
290300
}
291301

@@ -301,6 +311,18 @@ class Class extends UserType {
301311
not this.implicitCopyAssignmentOperatorDeleted() and
302312
forall(CopyAssignmentOperator ca | ca = this.getAMemberFunction() |
303313
ca.isCompilerGenerated() and not ca.isDeleted()
314+
) and
315+
(
316+
not this instanceof ClassTemplateInstantiation
317+
or
318+
this.(ClassTemplateInstantiation).getTemplate().hasImplicitCopyAssignmentOperator()
319+
) and
320+
(
321+
not this instanceof PartialClassTemplateSpecialization
322+
or
323+
this.(PartialClassTemplateSpecialization)
324+
.getPrimaryTemplate()
325+
.hasImplicitCopyAssignmentOperator()
304326
)
305327
}
306328

cpp/ql/test/library-tests/special_members/generated_copy/ctor.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
| difference::Base | can | does NOT | have implicit copy constructor |
1212
| difference::OnlyAssign | can NOT | does NOT | have implicit copy constructor |
1313
| difference::OnlyCtor | can | does | have implicit copy constructor |
14-
| instantiated_explicit_ctor::Wrapper<int> | can | does | have implicit copy constructor |
14+
| instantiated_explicit_ctor::Wrapper<int> | can | does NOT | have implicit copy constructor |
1515
| moves::MoveAssign | can NOT | does NOT | have implicit copy constructor |
1616
| moves::MoveCtor | can NOT | does NOT | have implicit copy constructor |
1717
| private_cc::C | can | does NOT | have implicit copy constructor |

0 commit comments

Comments
 (0)