https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100666
Bug ID: 100666
Summary: warning: ignoring return value of 'constexpr _Tp&&
std::forward(typename
std::remove_reference<_Tp>::type&) [with _Tp =
std::nullptr_t; typename
std::remove_reference<_Tp>::type = std::nullptr_t]',
declared with attribute 'nodiscard' [-Wunused-result]
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mh+gcc at glandium dot org
Target Milestone: ---
(Note I'm not entirely sure this is a GCC bug, but it doesn't happen with GCC <
11 and with clang)
Reduced testcase:
```
#include <utility>
extern void foo(...);
template <typename... Ts>
void bar(Ts&&... aArgs) {
foo(std::forward<Ts>(aArgs)...);
}
void qux() {
bar(nullptr);
}
```
This emits the following warning:
```
<source>: In instantiation of 'void bar(Ts&& ...) [with Ts =
{std::nullptr_t}]':
<source>:11:8: required from here
<source>:7:25: warning: ignoring return value of 'constexpr _Tp&&
std::forward(typename std::remove_reference<_Tp>::type&) [with _Tp =
std::nullptr_t; typename std::remove_reference<_Tp>::type = std::nullptr_t]',
declared with attribute 'nodiscard' [-Wunused-result]
7 | foo(std::forward<Ts>(aArgs)...);
| ~~~~~~~~~~~~~~~~^~~~~~~
In file included from
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/bits/stl_pair.h:59,
from
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/utility:70,
from <source>:1:
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/bits/move.h:77:5: note:
declared here
77 | forward(typename std::remove_reference<_Tp>::type& __t) noexcept
| ^~~~~~~
```
(https://godbolt.org/z/GW3xf71n3)
Incidentally, using the x86-64 gcc (static analysis) on compiler explorer fails
with:
```
during IPA pass: analyzer
<source>: In function 'void qux()':
<source>:11:9: internal compiler error: in make_region_for_type, at
analyzer/region-model.cc:5973
11 | bar(nullptr);
| ^~~~~~~
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.
```