[clang] [Sema] Default arguments for template parameters affect ContainsUnexpandedPacks (PR #99880)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 23 06:52:00 PDT 2024


================
@@ -61,27 +68,34 @@ TemplateParameterList::TemplateParameterList(const ASTContext& C,
 
     bool IsPack = P->isTemplateParameterPack();
     if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
-      if (!IsPack && NTTP->getType()->containsUnexpandedParameterPack())
-        ContainsUnexpandedParameterPack = true;
+      if (!IsPack) {
+        if (NTTP->getType()->containsUnexpandedParameterPack())
+          ContainsUnexpandedParameterPack = true;
+        else if (DefaultArgumentContainsUnexpandedPack(*NTTP))
+          ContainsUnexpandedParameterPack = true;
+      }
----------------
ilya-biryukov wrote:

Great point, sorry for missing this, I haven't given it another thought after adding the lambda.
Less nesting is a good win, PTAL.

I've been also thinking about changing
```cpp
    } else if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P)) {
      if (!IsPack &&
          (TTP->getTemplateParameters()->containsUnexpandedParameterPack() ||
           DefaultArgumentContainsUnexpandedPack(*TTP))) {
```
to 
```cpp
    } else if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P); TTP && !IsPack &&
          (TTP->getTemplateParameters()->containsUnexpandedParameterPack() ||
           DefaultArgumentContainsUnexpandedPack(*TTP))) {
```

but ultimately decided against that to keep the nesting consistent across all three branches.

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


More information about the cfe-commits mailing list