我一直沒有找到更好的標題,但如果您有正確的想法,可隨時修改它。實際上,它總比GCC vs clang反正。變量模板和函數的指針:什麼編譯器是正確的?
我試圖找出什麼是錯在此代碼:
template <typename... T>
struct S;
template <typename T, typename... U>
struct S<T, U...>: S<U...> {
using S<U...>::f;
template<void(*F)(const T &)>
void f() { }
};
template<>
struct S<> {
void f();
};
template<typename... T>
struct R: S<T...> {
using S<T...>::f;
template<typename U, void(*F)(const U &)>
void g() {
this->template f<F>();
}
};
void h(const double &) { }
int main() {
R<int, double> r;
r.g<double, h>();
}
它編譯與GCC 4.9(見here),但它不與鐺3.8編譯.0(見here)。
哪個編譯器是正確的,爲什麼?
此外,我能做些什麼來查看編譯器編譯的代碼?
這很奇怪(還在測試),現在我可以建議在問題中添加標誌「variadic-templates」。 – Radek
看來ICC也無法編譯這個:https://godbolt.org/g/N67e2z – NathanOliver
也許與[此問題]相關(http://stackoverflow.com/questions/8629839/c-candidate-template-ignored -invalid-explicit-specified-argument-for-templ)或[this question](http://stackoverflow.com/questions/33872039/invalid-explicitly-specified-argument-in-clang-but-successful-compilation-in -GCC)? – callyalater