Issue 182285
Summary Type of template auto value parameter ignored in function call lookup
Labels new issue
Assignees
Reporter andyg1001
    I can write a simple compile-time type-value map class as follows:

```
template <typename T, auto V>
struct TypeValuePair { };

template <typename... TypeValuePairs>
struct TypeValueMap
  {
  struct MapItems : TypeValuePairs... { };

  template <typename T, auto V>
  static constexpr auto Lookup(TypeValuePair<T, V>*)
 { return V; }

  template <auto V, typename T>
  static T Lookup(TypeValuePair<T, V>*);

  template <typename T>
  static constexpr auto ValueFor = Lookup<T>((MapItems*)nullptr);

  template <auto V>
 using TypeFor = decltype(Lookup<V>((MapItems*)nullptr));
 };
```

However, under clang up to trunk, the two lines in the test code below fail to compile with the error **no matching function for call to 'Lookup'** on the lines marked `//***`

```
struct A; struct B; struct C;
enum class Values { A, B, C };

using Map = TypeValueMap<
 TypeValuePair<A, Values::A>,
                TypeValuePair<B, Values::B>,
                TypeValuePair<C, Values::C>,
 TypeValuePair<struct Other, 0>
 >;

static_assert(Map::ValueFor<A> == Values::A, "");
static_assert(Map::ValueFor<B> == Values::B, "");
static_assert(Map::ValueFor<C> == Values::C, "");
static_assert(Map::ValueFor<struct Other> == 0, "");

static_assert(std::is_same<Map::TypeFor<Values::A>, A>::value, "");     //***
static_assert(std::is_same<Map::TypeFor<Values::B>, B>::value, "");
static_assert(std::is_same<Map::TypeFor<Values::C>, C>::value, "");
static_assert(std::is_same<Map::TypeFor<0>, struct Other>::value, "");  //***
```

GCC, by comparison, compiles the code fine.  See https://godbolt.org/z/6Gz3x5qns.

My assumption is that in function call matching, the template type of `auto V` is not used to distinguish between `Values::A` in `TypeValuePair<A, Values::A>` and `0` in `TypeValuePair<struct Other, 0>`.  Both evaluate to an integer of value 0, but the compiler should be able to determine that they are, in fact, independent types and be able to "find" the right call to `Lookup`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to