-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Sema] Diagnose by-value copy constructors in template instantiations #130866
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
Changes from all commits
80e764f
4fe1d93
12d9237
790d151
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify %s | ||
|
||
template<class T, class V> | ||
struct A{ | ||
A(); // expected-note{{candidate constructor not viable: requires 0 arguments, but 1 was provided}} | ||
A(A&); // expected-note{{candidate constructor not viable: expects an lvalue for 1st argument}} | ||
A(A<V, T>); // expected-error{{copy constructor must pass its first argument by reference}} | ||
}; | ||
|
||
void f() { | ||
A<int, int> a = A<int, int>(); // expected-note{{in instantiation of template class 'A<int, int>'}} | ||
A<int, double> a1 = A<double, int>(); // No error (not a copy constructor) | ||
} | ||
|
||
// Test rvalue-to-lvalue conversion in copy constructor | ||
A<int, int> &&a(void); | ||
void g() { | ||
A<int, int> a2 = a(); // expected-error{{no matching constructor}} | ||
} | ||
|
||
template<class T, class V> | ||
struct B{ | ||
B(); | ||
template<class U> B(U); // No error (templated constructor) | ||
}; | ||
|
||
void h() { | ||
B<int, int> b = B<int, int>(); // should use implicit copy constructor | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test for @hubert-reinterpretcast comment here Can you add tests for something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review! I’ll add tests for the A<int, double> case and update the PR shortly. |
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.
Did you run clang-format on this? I am surprised it would leave the
)
on the line like that but maybe I am off.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.
Thank you for catching this, and I am so sorry for the oversight.
I forgot to run clang-format before merging.
Should I submitt a follow-up PR to fix the formatting issues?
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.
I missed it too, sorry.
yes, feel free to submit a new pr. thanks