[clang] [clang] WIP: Warn on mismatched RequiresCapability attributes (PR #67520)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 5 11:40:53 PDT 2023


AaronBallman wrote:

> There's a problem with this attribute where the declaration in a header file doesn't have the attribute, but the definition in the source file has. As a result, the attribute doesn't take effect when just the header file is included.

Errr, that's the behavior of basically all inheritable attributes -- the design idea there is that the attribute is additive information that's only visible from the declaration with the attribute onward. So I think some users will appreciate this warning because they might not have been aware that the attribute was not really doing much for them, but I also think some users will be frustrated because they've done things like:
```
// Source.cpp
void func();

void foo() {
  func(); // Doesn't know about the attribute, but that's intentional for whatever reason.
}

ATTR void func();

void bar() {
  func();  // Does see the attribute
}

void func() {}

void baz() {
  func(); // Still sees the attribute
}
```
I could imagine this being useful for `RequiresCapability` in cases where you only want to require the capability internally as an implementation detail, but not make it part of the public interface of the function.

@aaronpuchert -- do you have thoughts here?

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


More information about the cfe-commits mailing list