https://github.com/Rajveer100 created https://github.com/llvm/llvm-project/pull/81251
Resolves Issue #80963 As described in the snippet of the issue, `A<T,V>` is correctly detected while it fails to reject in other cases. >From c931dd64e63817619c6b7f649828580b3fb2e6ec Mon Sep 17 00:00:00 2001 From: Rajveer <rajveer.develo...@icloud.com> Date: Fri, 9 Feb 2024 19:20:39 +0530 Subject: [PATCH] [clang] Clang should detect illegal copy constructor with template class as its parameter Resolves Issue #80963 --- clang/lib/Sema/SemaDeclCXX.cpp | 2 +- clang/test/SemaCXX/GH80963.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/GH80963.cpp diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index ab8a967b06a456..9778679ee40d47 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -10918,7 +10918,7 @@ void Sema::CheckConstructor(CXXConstructorDecl *Constructor) { // parameters have default arguments. if (!Constructor->isInvalidDecl() && Constructor->hasOneParamOrDefaultArgs() && - Constructor->getTemplateSpecializationKind() != + Constructor->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) { QualType ParamType = Constructor->getParamDecl(0)->getType(); QualType ClassTy = Context.getTagDeclType(ClassDecl); diff --git a/clang/test/SemaCXX/GH80963.cpp b/clang/test/SemaCXX/GH80963.cpp new file mode 100644 index 00000000000000..55779e6ff191b7 --- /dev/null +++ b/clang/test/SemaCXX/GH80963.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template < class T, class V > struct A +{ + A (); + A (A &); + A (A < V,T >); + // expected-error@-1 {{copy constructor must pass its first argument by reference}} +}; + +void f () +{ + A <int, int> (A < int, int >()); + // expected-note@-1 {{in instantiation of template class 'A<int, int>' requested here}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits