[clang] [clang] Check `std::initializer_list` more strictly (PR #133822)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 31 20:28:54 PDT 2025
================
@@ -12071,6 +12071,37 @@ NamespaceDecl *Sema::getOrCreateStdNamespace() {
return getStdNamespace();
}
+/// Check that the template-head of this class template is acceptable for
+/// a declaration of 'std::initializer_list', and optionally diagnose if
+/// it is not.
+/// \returns true if any issues were found.
+static bool CheckStdInitializerList(Sema &S, ClassTemplateDecl *Template,
+ bool Diagnose) {
+ TemplateParameterList *Params = Template->getTemplateParameters();
+ int ErrorKind = -1;
+
+ if (Params->size() != 1)
+ ErrorKind = 0; // must have exactly one template parameter
+ else if (Template->hasAssociatedConstraints())
+ ErrorKind = 1; // cannot have associated constraints
+ else {
+ auto *Param = dyn_cast<TemplateTypeParmDecl>(Params->getParam(0));
----------------
tbaederr wrote:
```suggestion
const auto *Param = dyn_cast<TemplateTypeParmDecl>(Params->getParam(0));
```
I think the `Template` parameter can be const as well?
https://github.com/llvm/llvm-project/pull/133822
More information about the cfe-commits
mailing list