clang bug? namespaced template class' friend

后端 未结 3 1196
不知归路
不知归路 2021-02-19 11:21

The following code which doesn\'t compile under clang but does under gcc and VS:

template class bar;

namespace NS
{
    template

        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-19 12:09

    Changing the code to

    template class bar;
    
    namespace NS
    {
        template
        class foo
        {
            foo() {}
    
            template friend class ::bar;
        };
    }
    
    template
    class bar
    {
    public:
        bar()
        {
            NS::foo f;
        }
    };
    
    
    int main(int, char **)
    {
        bar b;
    
        return 0;
    }
    

    compiles with clang. The problem seems to be the namespace lookup. The code

    template friend class bar;
    

    actually declared the class NS::bar a friend of NS::foo, so foo should not have been affected. My guess would be that clang is standard conformant and the code should not compile.

提交回复
热议问题