Type of template auto value parameter ignored in function call lookup
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
I can write a simple compile-time type-value map class as follows:
```c++
template
struct TypeValuePair { };
template
struct TypeValueMap
{
struct MapItems : TypeValuePairs... { };
template
static constexpr auto Lookup(TypeValuePair*)
{ return V; }
template
static T Lookup(TypeValuePair*);
template
static constexpr auto ValueFor = Lookup((MapItems*)nullptr);
template
using TypeFor = decltype(Lookup((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 `//***`
```c++
struct A; struct B; struct C;
enum class Values { A, B, C };
using Map = TypeValueMap<
TypeValuePair,
TypeValuePair,
TypeValuePair,
TypeValuePair
>;
static_assert(Map::ValueFor == Values::A, "");
static_assert(Map::ValueFor == Values::B, "");
static_assert(Map::ValueFor == Values::C, "");
static_assert(Map::ValueFor == 0, "");
static_assert(std::is_same, A>::value, ""); //***
static_assert(std::is_same, B>::value, "");
static_assert(std::is_same, C>::value, "");
static_assert(std::is_same, 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` and `0` in `TypeValuePair`. 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`.
Contributor guide
Assessment
This issue has not been assessed yet.