https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118230
Bug ID: 118230
Summary: `std::is_invocable` gives wrong result when the tested
function returns `auto`
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: one.last.kiss at outlook dot com
Target Milestone: ---
A very easy-to-understand single file:
#include <utility>
#include <type_traits>
struct A {
struct B {
auto operator()(const auto& i) const /* -> std::size_t */ {
return std::hash<int>{}(i);
}
};
static_assert(
std::is_invocable_v<const B&, const int&>
); // FAILED!!!
};
int main() { A{}; }
Just use `g++ -std=c++26 a.cpp -o a.exe` to compile it.
The error message is:
a.cpp:10:12: error: static assertion failed
10 | std::is_invocable_v<const B&, const int&>
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The workaround is to un-comment the "/* -> std::size_t */".
(Thanks to 康桓瑋 in his comment:
<https://stackoverflow.com/questions/79302550/#comment139842516_79302550>.)
Here is a read-world case: <https://stackoverflow.com/q/79302550>.
However, `g++` sometimes works well. E.g.,
<https://github.com/shynur/ipcator/blob/d0740607bdc8ba45c7a88f3023374c81a797daf8/include/ipcator.hpp#L637>.
Clone this repo (commit d07406) then run
`g++ -std=c++26 -Iinclude src/main.cpp -o main.exe`; there's no error or
warning. I don't know why it can pass the compilation check, and it's
difficult for me to cut it down to a minimal reproducible example; I'm sorry.
Output of `g++ -v`:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --enable-languages=c++ --disable-multilib
--enable-checking=release --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20241224 (experimental) (GCC)
--
shynur