-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang] Clang should detect illegal copy constructor with template class as its parameter #81251
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-clang Author: Rajveer Singh Bharadwaj (Rajveer100) ChangesResolves Issue #80963 As described in the snippet of the issue, Full diff: https://github.com/llvm/llvm-project/pull/81251.diff 2 Files Affected:
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}}
+}
|
@cor3ntin the fix looks like the one you recommended but that is quite a lot of tests that fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs a release note.
Could you merge main inside that branch? There are some test failures (which i hope are unrelated). Thanks |
c931dd6
to
7c58bd5
Compare
5c5a91d
to
4bb6d4d
Compare
…ass as its parameter Resolves llvm#80963
4bb6d4d
to
bf51e9d
Compare
I have removed this entirely, although it may still not be optimal, it did reduce few more test failures: Constructor->hasOneParamOrDefaultArgs() &&
Constructor->getTemplateSpecializationKind() !=
TSK_ImplicitInstantiation Any particular suggestions apart from updating the tests? |
I think we should check |
Resolves #80963
As described in the snippet of the issue,
A<T,V>
is correctly detected while it fails to reject in other cases.