[clang] [Clang][Sema] Reject template arguments not equivalent to their copies (part of P2308R1) (PR #193754)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 25 21:23:47 PDT 2026
================
@@ -7272,14 +7338,10 @@ 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.
+ // TODO: Remove `ParamType->isRecordType()` in condition?
----------------
zwuis wrote:
I thought this would improve performance but I'm not sure without benchmark. Removed the TODO.
https://github.com/llvm/llvm-project/pull/193754
More information about the cfe-commits
mailing list