[clang] [Clang][Sema] Reject template arguments not equivalent to their copies (part of P2308R1) (PR #193754)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 26 01:51:06 PDT 2026


================
@@ -7272,14 +7359,9 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
     return Arg;
   }
 
-  // Avoid making a copy when initializing a template parameter of class type
-  // from a template parameter object of the same type. This is going beyond
-  // the standard, but is required for soundness: in
-  //   template<A a> struct X { X *p; X<a> *q; };
-  // ... we need p and q to have the same type.
-  //
-  // Similarly, don't inject a call to a copy constructor when initializing
-  // from a template parameter of the same type.
+  // Fast path. A valid template parameter object is equivalent to its copy. No
+  // need to make a copy to check again when initializing a template parameter
+  // of class type from a template parameter object of the same type.
----------------
cor3ntin wrote:

Does that holds when the type has a non-trivial copy constructor? It would not necessarily, right?

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


More information about the cfe-commits mailing list