This code does not compile in Clang (6,7,8,9,trunk), but compiles just fine in GCC (7.1, 8.1, 9.1):
template<class T> struct TypeHolder { using type = T; };
template<int i>
class Outer {
private:
template<class T>
static constexpr auto compute_type() {
if constexpr (i == 42) {
return TypeHolder<bool>{};
} else {
return TypeHolder<T>{};
}
}
public:
template<class T>
using TheType = typename decltype(Outer<i>::compute_type<T>())::type;
};
int main() {
Outer<42>::TheType<int> i;
}
Clang tells me:
<source>:17:49: error: 'compute_type' is a private member of 'Outer<42>'
… which of course it is, but I'm trying to access that member from inside the same class. I don't see why it should not be accessible there. Have I hit (and should I file) a Clang bug?
You can toy around with the code at Godbolt's compiler explorer.
friend int main();
stops Clang from complaining.Outer<42>
, notmain
- right? Looking even more like a bug to me now.std::result_of
work instead?