Rozważmy następujący:Częściowo specjalizujący się na zakaz typu parametru szablonu z niewłaściwego typu
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, "!");
}
dzyń kompiluje kod, gcc nie.
Jednak w poniższym spokrewnionych np
template <unsigned >
struct uint_ { };
template <int I> // NB: int, not unsigned
void foo(uint_<I>) { }
int main() {
foo(uint_<0>{});
}
oba kompilatory odrzucić bez wywołania funkcji dopasowywania foo
. zachowanie gcc jest spójne, clang nie jest - więc jeden lub drugi kompilator ma błąd dla jednego lub obu przykładów. Który kompilator jest poprawny?
Ładne i bezpośrednie. Zapisano jako [28010] (https://llvm.org/bugs/show_bug.cgi?id=28010) – Barry