Deducing auto& from const int in template parameters is impossible in partial specializations (original) (raw)

Code to Reproduce

See https://godbolt.org/z/rhKsWKdPz .

#include

template <auto& Value, int> struct test : std::false_type {};

template <auto& Value> struct test<Value, 0> : std::true_type {};

int main() { static constexpr int v = 42; static_assert(test<v, 0>::value); // error ?! }

<source>:11:19: error: static assertion failed due to requirement 'test<v, 0>::value'
   11 |     static_assert(test<v, 0>::value);
      |                   ^~~~~~~~~~~~~~~~~

Explanation

Clang is completely unable to deduce auto& in the partial specialization, leading to this failure. GCC accepts this code, as it should.

Note that replacing auto& with const auto& fixes this, but shouldn't be necessary.

Original post and discussion: https://stackoverflow.com/q/77768531/5740428