Issue |
142453
|
Summary |
[clang] [[nodiscard]] on return type of function pointer is ignored sometimes
|
Labels |
clang
|
Assignees |
|
Reporter |
tJener
|
```c++
#include <functional>
#include <utility>
struct [[nodiscard]] S {};
S (*get_fp())();
template <typename Func>
void f(Func fn) {
static_cast<Func>(fn)(); // Ignored
static_cast<Func&>(fn)(); // Ignored
static_cast<Func&&>(fn)(); // Ignored
std::move(fn)(); // Ignored
fn();
}
void i() {
f(get_fp());
f(std::bind(get_fp()));
get_fp()(); // Ignored
std::bind(get_fp())();
}
```
https://godbolt.org/z/Mje7nWh1r
---
When a function pointer returning a type marked `[[nodiscard]]` is invoked, it will sometimes not generate a `-Wunused-value` warning. As a comparison, it will generate the warning if wrapped in a `std::bind`.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs