mercredi 26 avril 2017

instantiation of public alias template that refers to private function template fails (clang)

I noticed some unique behaviour of Clang in the following scenario:

There is a class foo that contains a private member function template function_template. foo also declares the non-nested struct bar as friend:

struct bar;
class foo {
    friend struct ::bar;
    template<typename T> void function_template() {}
};

Inside of bar the member alias template type is declared that refers to the return type of foo's member function template, like so:

struct bar {
   template<typename T> type = decltype(foo().function_template<T>());
}

Using clang, the compiler is not able to instantiate the public alias template bar::type for any template argument:

#include <typeinfo>
#include <iostream>
int main {
    std::cout << typeid(bar::type<int>).name() << std::endl;
    // error : 'function_template' is a private member of 'foo'
}

Is this behaviour standard conforming? MSVC and GCC both perform this instantiation. Also Clang performs the instantiation of other alias templates referring to private members of a friend class.

My extended test of the alias template behaviour can be found here: http://ift.tt/2pmZjoS

Aucun commentaire:

Enregistrer un commentaire