page =
url = https://quuxplusone.github.io/blog
arthur o'dwyer – stuff mostly about c++
Here’s a C++ riddle for you: When does
std::invoke
not invoke?
struct Incomplete; Incomplete&& give(); void take(Incomplete&&); void okay() { take(give()); // OK, valid C++ } void bad() { std::invoke(take, give()); // UB }
Given this code ( Godbolt ), libc++ and Microsoft accept the call to
invoke
, but libstdc++ rejects with a spew of errors:
type_traits:3027:7: error: static_assert failed due to requirement 'std::__is_complete_or_unbounded(std::__type_identity<Incomplete>{})' "each argument type must be a complete class or an unbounded array" static_assert((std::__is_complete_or_unbounded( ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~