'template argument from aliased lambda is invalid

(c++20 mode for all of the following)

I am trying to use std unordered_map with std::reference_wrapper keys to avoid copying somewhat expensive keys, that are stored elsewhere anyway. The referenced type is hashable, but I need to provide forward hasher functors and comparator functors, which I have done as so:

template < typename T >
using default_ref_hasher = decltype([](const std::reference_wrapper< T >& value) {
    return std::hash< std::remove_cvref_t< T > >{}(value.get());
});
template < typename T >
using default_ref_comparator = decltype([](const std::reference_wrapper< T >& ref1,
                                            const std::reference_wrapper< T >& ref2) {
    return ref1.get() == ref2.get();
});

those are then used in my templated class

template <typename Action>
class Myclass {

   std::unordered_map<
      std::reference_wrapper< const Action >,
      double,
      default_ref_hasher< const Action >,
      default_ref_comparator< const Action > >
      map{};

};

I feel as though this is valid c++ code, however, I get the following errors on GCC 11+:

<source>:24:46: error: template argument 3 is invalid
   24 |       default_ref_comparator< const Action > >
      |                                              ^
<source>:24:46: error: template argument 4 is invalid
<source>:20:9: error: '<expression error>' in namespace 'std' does not name a type
   20 |    std::unordered_map<
      |         ^~~~~~~~~~~~~~
   21 |       std::reference_wrapper< const Action >,
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   22 |       double,
      |       ~~~~~~~
   23 |       default_ref_hasher< const Action >,
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   24 |       default_ref_comparator< const Action > >
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ASM generation compiler returned: 1

as can be seen here on godbolt. If I compile instead with clang 13+ it does compile fine.

Is this a bug in GCC or does clang fail to check a mistake I made?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source