Consider the following:
template <unsigned >
struct uint_ { };
template <class >
struct X {
static constexpr bool value = false;
};
template <int I> // NB: int, not unsigned
struct X<uint_<I>> {
static constexpr bool value = true;
};
int main() {
static_assert(X<uint_<0>>::value, "!");
}
clang compiles the code, gcc does not.
However, in the following highly related example:
template <unsigned >
struct uint_ { };
template <int I> // NB: int, not unsigned
void foo(uint_<I> ) { }
int main() {
foo(uint_<0>{} );
}
both compilers reject with no matching function call to foo
. gcc's behavior is consistent, clang's is not - so one or the other compiler has a bug for one or both examples. Which compiler is correct?
GCC is correct. [temp.deduct.type]/17:
If
P
has a form that contains<i>
, and if the type of the corresponding value ofA
differs from the type ofi
, deduction fails.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With