[clang] [clang][Sema][ThreadSafety] Accept attributes without arguments as meaning 'this' (PR #242937)
Marco Elver via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 23 07:50:39 PST 2026
================
@@ -352,16 +352,23 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
if (Sidx == AL.getNumArgs()) {
// If we don't have any capability arguments, the attribute implicitly
// refers to 'this'. So we need to make sure that 'this' exists, i.e. we're
- // a non-static method, and that the class is a (scoped) capability.
- const auto *MD = dyn_cast<const CXXMethodDecl>(D);
- if (MD && !MD->isStatic()) {
- const CXXRecordDecl *RD = MD->getParent();
+ // a non-static method, and that the class is a (scoped) capability. A
+ // function pointer field is likewise called through an object, which the
+ // attribute then refers to.
+ const RecordDecl *RD = nullptr;
+ if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
+ if (!MD->isStatic())
+ RD = MD->getParent();
+ } else if (const auto *FD = dyn_cast<FieldDecl>(D)) {
+ RD = FD->getParent();
+ }
+ if (RD) {
// FIXME -- need to check this again on template instantiation
if (!checkRecordDeclForAttr<CapabilityAttr>(RD) &&
----------------
melver wrote:
For completeness sake it makes sense.
Although I don't think anybody uses the C++11 spelling intermixed with the GNU spelling, so I'd leave that one aside until somebody actually asks for it.
The template one might be worth fixing, if that's something that people actually do.
https://github.com/llvm/llvm-project/pull/242937
More information about the cfe-commits
mailing list