Consider the following
template <typename T1>
struct OuterFoo {
template <typename T2>
struct InnerFoo {
InnerFoo(T2 v2) {}
};
explicit OuterFoo(T1 v1) {}
};
int main() {
OuterFoo outer_foo{6};
OuterFoo<int>::InnerFoo inner_foo{3};
return 0;
}
clang refuses to compile this, stating "no viable constructor or deduction guide for deduction of template arguments of 'InnerFoo'" - Gcc on the other hand compiles without problems.
Is the provided example correct (as by the standard) usage of CTAD and is clang at fault here?
If a deduction guide is provided, clang compiles fine, but gcc doesn't accept the guide: https://godbolt.org/z/4b-9Cr
template <typename T1>
struct OuterFoo {
template <typename T2>
struct InnerFoo {
InnerFoo(T2 v2) {}
};
// This Template Deduction Guide is required in clang 6
// for the example to compile.
// GCC compiles without this TDG but reports an error
// with it
// "deduction guide ‘OuterFoo<T1>::InnerFoo(T2) -> OuterFoo<T1>::InnerFoo<T2>’
// must be declared at namespace scope"
template<typename T2> InnerFoo(T2 v2) -> InnerFoo<T2>;
// ...but no TDG is required for OuterFoo
explicit OuterFoo(T1 v1) {}
};
int main() {
OuterFoo outer_foo{6};
OuterFoo<int>::InnerFoo inner_foo{3};
return 0;
}
What is the state of CTAD for member template classes in clang and gcc? Is it simply not there yet?
What is the state of CTAD for member template classes in clang and gcc? Is it simply not there yet?
As per the language features support page for GCC , CTAD is available for versions 7 and above.
As per the language features support page for Clang , CTAD is available for versions 7 and above.
However, note that there have been defects reported and resolved in later versions of these implementations.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.