[clang] [clang] Output a warning when [[lifetimebound]] attribute is applied on a function parameter while the function returns void (PR #113460)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 23 07:47:55 PDT 2024
================
@@ -6970,6 +6970,18 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
}
}
}
+
+ for (unsigned int I = 0; I < FD->getNumParams(); ++I) {
+ const ParmVarDecl *P = FD->getParamDecl(I);
+
+ // The [[lifetimebound]] attribute can be applied to a function parameter
+ // only if the function returns a value.
+ if (auto *A = P->getAttr<LifetimeBoundAttr>()) {
----------------
usx95 wrote:
An interesting case that [came up](https://github.com/llvm/llvm-project/issues/107556#issuecomment-2333906528) involves dependent return type.
I think we should not be showing this error if there is a dependent return type.
```cpp
template <class T, class R = void> R foo(const T& t [[clang::lifetimebound]]);
foo<int>(1);
const int& r = foo<int, int>(1);
```
There is no way to fix this for one instantiation and not for the other so we should be accepting these.
Can you also add test involving tempates with and without dependent return types.
https://github.com/llvm/llvm-project/pull/113460
More information about the cfe-commits
mailing list