[clang] [clang] Fix bad error recovery when classes are defined inside template (PR #142278)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Sat May 31 10:11:56 PDT 2025


================
@@ -220,6 +220,14 @@ static ExprResult EvaluateAtomicConstraint(
     if (Inst.isInvalid())
       return ExprError();
 
+    if (const TemplateTypeParmType *TTPT =
+        dyn_cast<TemplateTypeParmType>(AtomicExpr->getType().getDesugaredType(S.Context))) {
+      TemplateTypeParmDecl *TTPD = TTPT->getDecl();
+      if (TTPD->isInvalidDecl()) {
+        return ExprError();
+      }
+    }
+
----------------
mizvekov wrote:

Thanks for working on this!

So this fixes the problem too narrowly, only does anything for concepts.

I think a more general way to fix this, would be to make the type of a `TemplateTypeParmType` be non-dependent when it is invalid.

Since the type for a TTP decl is created when the declaration is created,  you could use `TTPDecl->setTypeForDecl(` to change its type to the built-in int type, which is a common error recovery strategy in clang.
You can do that at the same time as you set the TTP decl as invalid.

Double check you are doing this early enough: You want to change the type before the template parameter has any chance to be used.

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


More information about the cfe-commits mailing list