Remove is_invocable static assertions in _Rb_tree?

Jonathan Wakely jwakely@redhat.com
Thu May 31 10:31:00 GMT 2018


On 31/05/18 07:31 +0200, François Dumont wrote:
>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
>>     // _GLIBCXX_RESOLVE_LIB_DEFECTS
>>     // 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.
>>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85965
>>
>>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 ?

But in PR 85965 the types are complete. const Biz* is a complete type,
and Bar is a complete type.

In any case, that would cause ODR violations by giving different
results before and after the types are complete.

>It 
>would for sure limit its usage but still be of interest.
>
>Otherwise, +1 to remove it. Is the compiler error message that awful ?

Some people are really bad at reading error messages. If the first
line is a static assertion with a message it can tell them what's
wrong, so they don't just get confused by the errors. But I think we
have to just remove the assertions.



More information about the Libstdc++ mailing list