https://github.com/Rajveer100 updated https://github.com/llvm/llvm-project/pull/81251
>From bf51e9df3333b160ec32b3f3a7d052c1da24f06a 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 #80963 --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaDeclCXX.cpp | 4 +--- clang/test/SemaCXX/GH81251.cpp | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 clang/test/SemaCXX/GH81251.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 529dd783ab7382..d30e13b0b1b62c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -281,6 +281,8 @@ Bug Fixes to C++ Support a requires-clause lie at the same depth as those of the surrounding lambda. This, in turn, results in the wrong template argument substitution during constraint checking. (`#78524 <https://github.com/llvm/llvm-project/issues/78524>`_) +- Clang now detects illegal copy constructor with template class as its parameter. + Fixes (`#80963 https://github.com/llvm/llvm-project/issues/80963>`_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 7c009d9c8ec093..622bf0c258f138 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -10921,9 +10921,7 @@ void Sema::CheckConstructor(CXXConstructorDecl *Constructor) { // either there are no other parameters or else all other // parameters have default arguments. if (!Constructor->isInvalidDecl() && - Constructor->hasOneParamOrDefaultArgs() && - Constructor->getTemplateSpecializationKind() != - TSK_ImplicitInstantiation) { + Constructor->hasOneParamOrDefaultArgs()) { QualType ParamType = Constructor->getParamDecl(0)->getType(); QualType ClassTy = Context.getTagDeclType(ClassDecl); if (Context.getCanonicalType(ParamType).getUnqualifiedType() == ClassTy) { diff --git a/clang/test/SemaCXX/GH81251.cpp b/clang/test/SemaCXX/GH81251.cpp new file mode 100644 index 00000000000000..a3e0ba07728dcc --- /dev/null +++ b/clang/test/SemaCXX/GH81251.cpp @@ -0,0 +1,17 @@ +// 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}} + + A <int, double> (A < int, double >()); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits