[clang] [clang][ThreadSafety] Name a member through 'this' in a parameter's attribute during parsing attribute (PR #241077)
Jameson Nash via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 16 09:45:55 PST 2026
================
@@ -2572,6 +2572,18 @@ bool TemplateInstantiator::TransformFunctionTypeParams(
}));
if (Failed)
return true;
+ // An attribute on a parameter of a non-static member function names a member
+ // through 'this', unqualified as in the parser, which has not yet seen the
+ // function's cv-qualifiers; see Parser::ParseAttributeArgsCommon.
+ CXXRecordDecl *ThisContext = nullptr;
+ const auto *It = llvm::find_if(Params, [](ParmVarDecl *P) { return P; });
+ if (!LateAttrs.empty() && It != Params.end())
+ if (auto *MD = dyn_cast<CXXMethodDecl>((*It)->getDeclContext());
+ MD && MD->isImplicitObjectMemberFunction() &&
+ !MD->getParent()->isLambda())
+ ThisContext = dyn_cast_or_null<CXXRecordDecl>(
+ SemaRef.FindInstantiatedDecl(Loc, MD->getParent(), TemplateArgs));
+ Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, Qualifiers());
----------------
vtjnash wrote:
Yes, I'd happened to be re-reviewing and revising this PR at exactly the same time you were, and I think the revised implementation addressed a lot of the issues you were seeing. The crux of the issue with the first implementation seems to be that much of the info required to implement the attribute semantics correctly (such as whether it is a `static` function of the class) is not available until about the time of late-parsing, so we have to adopt late-parsing more widely already if we want correct-parsing at all (instead of hacking it in TSA to recover the correct parse). The PR now also includes a commit to warn when the new parse would change the meaning of an expression (due to conflicting variables names). As reviewers commented before, we might end up deciding to delete those warnings before the release. I've left the warnings as a separate commit here, so it can be dropped or squashed, and added a comment advising them all to be dropped when appropriate.
https://github.com/llvm/llvm-project/pull/241077
More information about the cfe-commits
mailing list