Skip to content

Commit bf51e9d

Browse files
committed
[clang] Clang should detect illegal copy constructor with template class as its parameter
Resolves #80963
1 parent 12d29cd commit bf51e9d

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ Bug Fixes to C++ Support
281281
a requires-clause lie at the same depth as those of the surrounding lambda. This,
282282
in turn, results in the wrong template argument substitution during constraint checking.
283283
(`#78524 <https://github.com/llvm/llvm-project/issues/78524>`_)
284+
- Clang now detects illegal copy constructor with template class as its parameter.
285+
Fixes (`#80963 https://github.com/llvm/llvm-project/issues/80963>`_)
284286

285287
Bug Fixes to AST Handling
286288
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10921,9 +10921,7 @@ void Sema::CheckConstructor(CXXConstructorDecl *Constructor) {
1092110921
// either there are no other parameters or else all other
1092210922
// parameters have default arguments.
1092310923
if (!Constructor->isInvalidDecl() &&
10924-
Constructor->hasOneParamOrDefaultArgs() &&
10925-
Constructor->getTemplateSpecializationKind() !=
10926-
TSK_ImplicitInstantiation) {
10924+
Constructor->hasOneParamOrDefaultArgs()) {
1092710925
QualType ParamType = Constructor->getParamDecl(0)->getType();
1092810926
QualType ClassTy = Context.getTagDeclType(ClassDecl);
1092910927
if (Context.getCanonicalType(ParamType).getUnqualifiedType() == ClassTy) {

clang/test/SemaCXX/GH81251.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
3+
template < class T, class V > struct A
4+
{
5+
A ();
6+
A (A &);
7+
A (A < V,T >);
8+
// expected-error@-1 {{copy constructor must pass its first argument by reference}}
9+
};
10+
11+
void f ()
12+
{
13+
A <int, int> (A < int, int >());
14+
// expected-note@-1 {{in instantiation of template class 'A<int, int>' requested here}}
15+
16+
A <int, double> (A < int, double >());
17+
}

0 commit comments

Comments
 (0)