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.
This is core issue 1554. The standard is unclear how access checking is performed for alias templates (in the context of definition, or in the context of use).
The current direction is to check in the context of the definition, which would make your code well-formed.
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