ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.06k stars 437 forks source link

Concept error: satisfaction of atomic constraint '__is_constructible(T) [with Args = {I}; T = I]' depends on itself #1747

Open maichmueller opened 1 year ago

maichmueller commented 1 year ago

Hi,

the following concepts cause a cryptic error within the range-v3 v.0.12 library when used with GCC-11 or GCC-12 (linux):

template < typename MapLike >
concept mapping = requires(MapLike m) {
                     // has to be key-value-like to iterate over values and keys only repsectively
                     ranges::views::keys(m);
                     ranges::views::values(m);
                  };

template < typename MapLike, typename KeyType >
concept maps = mapping< MapLike >
               and std::is_convertible_v<    // value type has to be convertible to the Mapped Type
                  decltype(*(ranges::views::keys(std::declval< MapLike >()).begin())),
                  KeyType >;

the error message goes deep within the range-v3 concepts:

/opt/compiler-explorer/libs/rangesv3/0.12.0/include/range/v3/view/all.hpp: In instantiation of 'constexpr auto ranges::views::all_fn::operator()(T&&) const [with T = const Hashmap&]': /opt/compiler-explorer/libs/rangesv3/0.12.0/include/range/v3/view/all.hpp:91:35: required by substitution of 'template requires (viewable_range) && (input_range) && (kv_pairlike<decltype((declval<decltype(ranges::_::begin(static_cast<Rng& ()()noexcept (true)>(nullptr)()))&>)())>) ranges::keys_range_view<decltype (ranges::views::all(declval()))> ranges::views::keys_fn::operator()(Rng&&) const [with Rng = const Hashmap&]' :15:41: required by substitution of 'template requires maps<U, T> Hashmap::Hashmap(U&&) [with U = int]' /opt/compiler-explorer/libs/rangesv3/0.12.0/include/concepts/concepts.hpp:1153:13: required from 'constexpr auto ranges::views::all_fn::operator()(T&&) const [with T = Hashmap&]' /opt/compiler-explorer/libs/rangesv3/0.12.0/include/range/v3/view/all.hpp:91:35: required by substitution of 'template requires (viewable_range) && (input_range) && (kv_pairlike<decltype((declval<decltype(ranges::_::begin(static_cast<Rng& ()()noexcept (true)>(nullptr)()))&>)())>) ranges::values_view<decltype (ranges::views::all(declval()))> ranges::views::values_fn::operator()(Rng&&) const [with Rng = Hashmap&]' /opt/compiler-explorer/libs/rangesv3/0.12.0/include/range/v3/functional/invoke.hpp:140:34: required by substitution of 'template<class F, class ... Args> constexpr decltype ((F&&)(f)((Args&&(ranges::invoke_fn::operator()::args))...)) ranges::invoke_fn::operator()(F&&, Args&& ...) const [with F = ranges::views::values_fn; Args = {Hashmap&}]' /opt/compiler-explorer/libs/rangesv3/0.12.0/include/range/v3/functional/concepts.hpp:40:5: required by substitution of 'template<class Rng, class ViewFn> requires (viewable_range) && (invocable_view_closure<ViewFn, Rng>) constexpr auto ranges::views::view_closure_base_ns::operator|(Rng&&, ranges::views::view_closure) [with Rng = Hashmap&; ViewFn = ranges::views::values_fn]' :60:36: required from here /opt/compiler-explorer/libs/rangesv3/0.12.0/include/concepts/concepts.hpp:1151:21: required for the satisfaction of 'constructible_from<T, const T>' [with T = Hashmap] /opt/compiler-explorer/libs/rangesv3/0.12.0/include/concepts/concepts.hpp:1170:9: required for the satisfaction of 'copy_constructibleconcept' [with T = Hashmap] /opt/compiler-explorer/libs/rangesv3/0.12.0/include/concepts/concepts.hpp:1181:21: required for the satisfaction of 'copy_constructible' [with T = Hashmap] /opt/compiler-explorer/libs/rangesv3/0.12.0/include/concepts/concepts.hpp:1209:21: required for the satisfaction of 'copyable' [with T = Hashmap] /opt/compiler-explorer/libs/rangesv3/0.12.0/include/concepts/concepts.hpp:1217:21: required for the satisfaction of 'semiregular' [with T = Hashmap] cc1plus: error: satisfaction of atomic constraint 'is_constructible(T) [with Args = {const I}; T = I]' depends on itself /opt/compiler-explorer/libs/rangesv3/0.12.0/include/concepts/concepts.hpp:1151:21: required for the satisfaction of 'constructible_from<T, const T>' [with T = Hashmap] /opt/compiler-explorer/libs/rangesv3/0.12.0/include/concepts/concepts.hpp:1170:9: required for the satisfaction of 'copy_constructibleconcept' [with T = Hashmap] /opt/compiler-explorer/libs/rangesv3/0.12.0/include/concepts/concepts.hpp:1181:21: required for the satisfaction of 'copy_constructible' [with T = Hashmap] /opt/compiler-explorer/libs/rangesv3/0.12.0/include/concepts/concepts.hpp:1209:21: required for the satisfaction of 'copyable' [with T = Hashmap] /opt/compiler-explorer/libs/rangesv3/0.12.0/include/concepts/concepts.hpp:1217:21: required for the satisfaction of 'semiregular' [with T = Hashmap] cc1plus: error: satisfaction of atomic constraint 'is_constructible(T) [with Args = {const I}; T = I]' depends on itself

I am using this concept in my code to filter out maps over certain key types (maybe this isn't the best way) and this error has been bugging me for a while now.

Here is a godbolt link to verify the problem on GCC 11/12. It does work e.g. under clang 15: https://godbolt.org/z/dqj1YY9e4

The problem does not exist with std::ranges and GCC, but it does for clang now: https://godbolt.org/z/a88WMe66b