[clang] [Clang] Implement CWG2900 (PR #224291)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 30 01:52:14 PDT 2026
================
@@ -234,31 +234,39 @@ class NonTypeOrVarTemplateParmDecl {
const NamedDecl *Template;
};
-/// If the given expression is of a form that permits the deduction
-/// of a non-type template parameter, return the declaration of that
-/// non-type template parameter.
+/// If the given expression is of a form that names a non-type template
+/// parameter, return the declaration of that parameter. A null \p Depth
+/// accepts a parameter at any depth.
static NonTypeOrVarTemplateParmDecl
-getDeducedNTTParameterFromExpr(const Expr *E, unsigned Depth) {
+getNTTParameterFromExpr(const Expr *E, UnsignedOrNone Depth) {
// If we are within an alias template, the expression may have undergone
// any number of parameter substitutions already.
E = unwrapExpressionForDeduction(E);
if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl()))
- if (NTTP->getDepth() == Depth)
+ if (!Depth || NTTP->getDepth() == *Depth)
return NTTP;
// A pack-index-template-name is not deducible.
if (const auto *DTI = dyn_cast<DependentTemplateIdExpr>(E))
if (!DTI->getTemplateName().getAsPackIndexingTemplate() &&
- DTI->getParameter()->getDepth() == Depth)
+ (!Depth || DTI->getParameter()->getDepth() == *Depth))
return DTI->getParameter();
return nullptr;
}
+QualType Sema::getTypeOfConstantTemplateParameter(const TemplateArgument &A,
----------------
cor3ntin wrote:
The type of the parameter gets deduced from its value/argument
https://github.com/llvm/llvm-project/pull/224291
More information about the cfe-commits
mailing list