Clang (7, 8, trunk) rejects the following code
enum class E {};
inline static constexpr auto e = E{};
// inline static constexpr auto e = nullptr;
template<auto, int> class S;
template<int a, int b> class S<a, b> {};
template<int b> class S<e, b> {};
int main() {
S<0, 0> s;
}
with an error:
error: ambiguous partial specializations of 'S<0, 0>' note: partial specialization matches [with a = 0, b = 0] template<int a, int b> class S<a, b> {}; ^ note: partial specialization matches [with b = 0] template<int b> class S<e, b> {}; ^
Why is it ambiguous? How can
e
match0
? If I replaceE{}
withnullptr
, Clang stops complaining. This looks like a Clang's bug. GCC compiles it just fine.If it is a bug, what is a workaround? In my case, the
auto
parameter can be eitherE
(and only one valueE{}
) orint
. Then:template<auto, int, typename> class S_impl; template<int a, int b> class S_impl<a, b, int> {}; template<int b> class S_impl<e, b, E> {}; template<auto a, int b> using S = S_impl<a, b, decltype(a)>;
Is there a more succinct way?