https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93152

--- Comment #3 from DB <db0451 at gmail dot com> ---
The pointer-to-member-function and template argument deduction through it is
not required; rather, simply the presence of any other template argument in the
1st position is sufficient:

```
#include <concepts>
#include <type_traits>

struct WeirdBase {};
struct WeirdSub: WeirdBase {};

struct OtherBase {};
struct OtherSub: OtherBase {};

// Putting Result as 1st template argument makes derived_from<WeirdBase> fail,
#if 1
template <typename Foo, std::derived_from<WeirdBase> WeirdSub1>
// but putting derived_from<WeirdBase> 1st lets it compile without problem!
#else
template <std::derived_from<WeirdBase> WeirdSub1, typename Result>
#endif
auto
make_lambda()
{
        return []
#if 1
               (std::derived_from<WeirdSub1> auto&&,
                std::derived_from<OtherBase> auto&&)
        {
// If you do the following instead, both template arg orders work!!
#else
               (std::derived_from<WeirdBase> auto&& weird,
                std::derived_from<OtherBase> auto&&)
        {
                using WeirdSub2 = std::remove_reference_t< decltype(weird) >;
                static_assert( std::derived_from<WeirdSub2, WeirdSub1> );
#endif
        };
}

auto
main() -> int
{
#if 1
        auto const lambda = make_lambda<int, WeirdSub>();
#else
        auto const lambda = make_lambda<WeirdSub, int>();
#endif
        lambda( WeirdSub{}, OtherSub{} );

        return 0;
}
```

>>>
test3.cpp: In function ‘int main()’:
test3.cpp:44:33: error: no match for call to ‘(const make_lambda() [with Foo =
int; WeirdSub1 = WeirdSub]::<lambda(auto:1&&, auto:2&&)>) (WeirdSub, OtherSub)’
   44 |  lambda( WeirdSub{}, OtherSub{} );
      |                                 ^
test3.cpp:20:9: note: candidate: ‘make_lambda() [with Foo = int; WeirdSub1 =
WeirdSub]::<lambda(auto:1&&, auto:2&&)> [with auto:1 = WeirdSub; auto:2 =
OtherSub]’
   20 |  return []
      |         ^
test3.cpp:20:9: note: constraints not satisfied
In file included from test3.cpp:1:
/usr/include/c++/10/concepts: In instantiation of ‘make_lambda() [with Foo =
int; WeirdSub1 = WeirdSub]::<lambda(auto:1&&, auto:2&&)> [with auto:1 =
WeirdSub; auto:2 = OtherSub]’:
test3.cpp:44:33:   required from here
/usr/include/c++/10/concepts:67:13:   required for the satisfaction of
‘derived_from<auto:1, OtherSub>’
/usr/include/c++/10/concepts:67:28: note:   ‘OtherSub’ is not a base of
‘WeirdSub’
   67 |     concept derived_from = __is_base_of(_Base, _Derived)
>>>

Reply via email to