Issue 131458
Summary clang: regression - erroneous warning when calling `[[nodiscard]]` `static` function through a `std::forward`
Labels clang
Assignees
Reporter elbeno
    This code:
```cpp
#include <utility>

struct A {
    [[nodiscard]] static auto f() {
        return 42;
    }
};

template <typename T>
auto f(T &&t) {
    return std::forward<T>(t).f();
}

auto b = f(A{}) == 42;
```

https://godbolt.org/z/cxGvxM9bn

Provokes a warning:
```console
<source>:11:12: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
   11 | return std::forward<T>(t).f();
      |            ^~~~~~~~~~~~~~~ ~
<source>:14:10: note: in instantiation of function template specialization 'f<A>' requested here
   14 | auto b = f(A{}) == 42;
      |          ^
1 warning generated.
```

This seems to be a regression from clang-19.

This happens when:
 - the function called is `static`
 - we are calling it through member syntax with an object that is `std::forward`-ed
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to