[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
Sun Jun 1 08:45:28 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:
If you change the type for the TTPDecl to int, then that changes the type produced whenever a typename lookup is performed for that template parameter name, and the TTPDecl essentially becomes unreachable within the program. So any users of T wouldn't be able to figure out there was a template parameter there, and should see no dependency.
I suspect you might not be changing the type early enough, the type should be changed as soon as we figure out we are getting into a struct definition, before the template parameter could be used as a base class, inside an attribute, or in the class body.
https://github.com/llvm/llvm-project/pull/142278
More information about the cfe-commits
mailing list