Remove is_invocable static assertions in _Rb_tree?

François Dumont
Thu May 31 05:31:00 GMT 2018

On 29/05/2018 14:40, Jonathan Wakely wrote:
> I added these to _Rb_tree to try and help users who don't understand
> why they get errors for invalid comparison functions:
> #if __cplusplus >= 201103L
>      static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
>       "comparison object must be invocable with two arguments of key 
> type");
> # if __cplusplus >= 201703L
>      // 2542. Missing const requirements for associative containers
>      static_assert(is_invocable_v<const _Compare&, const _Key&, const 
> _Key&>,
>       "comparison object must be invocable as const");
> # endif // C++17
> #endif // C++11
> But the assertions fail for code that isn't obviously ill-formed e.g.
> We could move the assertions later, so they only happen when the
> comparison function is actually invoked. That might still give better
> diagnostics than the ill-formed call to the function. But it would
> mean duplicating them in lots of places (or at least putting them in
> some new function and calling that function from lots of places).
> Or we could just remove those assertions.
> Any other ideas?
Couldn't we limit the assertion to types with complete definition ? It 
would for sure limit its usage but still be of interest.

Otherwise, +1 to remove it. Is the compiler error message that awful ?

More information about the Libstdc++ mailing list