[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
Mon Jul 27 20:00:56 PDT 2026
================
@@ -7417,6 +7477,12 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
if (Value.isAddrLabelDiff())
return Diag(StartLoc, diag::err_non_type_template_arg_addr_label_diff);
+ if (ParamType->isRecordType() &&
+ !ParamType->isInstantiationDependentType() &&
----------------
zwuis wrote:
I initially thought this was the same issue as #84052, but I've just realized there are differences.
1. A `TemplateParamObjectDecl` of instantiation-dependent type is inserted into the cache map.
2. When checking template arguments of a non-dependent template id, we still use that `TemplateParamObjectDecl` from the cache map.
(The behavior described above matches #84052 up to this point.)
3. Because of that `TemplateParamObjectDecl`, the constraint is dependent (and remains so), so the constraint satisfaction check is deferred.
4. As a result, an invalid template id is accepted.
Possible fixes:
- Bail out if the type is instantiation-dependent, or
- Create a `TemplateParamObjectDecl` of the canonical type:
- if the type is instantiation-dependent, or
- always.
https://github.com/llvm/llvm-project/pull/193754
More information about the cfe-commits
mailing list