[clang] [Sema] Diagnose by-value copy constructors in template instantiations (PR #130866)

via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 12 00:02:59 PDT 2025


================
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template<class T, class V>
+struct A{
+    A();
+    A(A&);
+    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>'}}
+}
+
+template<class T, class V>
+struct B{
+    B();
+    template<class U> B(U); // No error (templated constructor)
+};
+
+void g() {
+    B<int, int> b = B<int, int>(); // should use implicit copy constructor
+}
----------------
cor3ntin wrote:

Can you add a test for @hubert-reinterpretcast comment here
https://github.com/llvm/llvm-project/issues/80963#issuecomment-2716322960

Can you add tests for something like
`A<int, double> a = A<double, int>();` // not a copy constructor


https://github.com/llvm/llvm-project/pull/130866


More information about the cfe-commits mailing list