Clang can't handle a template specialization using referenced template template, but GCC can

点点圈 提交于 2019-12-23 15:43:39

问题


I use a pattern like the following in my generic architecture. It compiles and runs correctly in GCC 5.2.0:

#include <iostream>
using namespace std;


template<class Baz>
class Foo
{
public:
    void foo(){cout<<"Foo method";}
};


template<template<class> class FooType>
class BarBase: public FooType<int>
{
public:    
    double bar() {cout<<"Generic bar";}
};

template<template<class> class FooType>
class Bar: public BarBase<FooType>
{
};

template<>
class Bar<Foo>: public BarBase<Foo>
{
public:
    void specialBar(){cout<<"Specialized bar";}
};

struct Aspect_Foo
{
    template<class Baz>
    using FooTrait = Foo<Baz>;
};

struct Aspect_Bar
{    
    template<template<class> class FooType>
    using BarTrait = Bar<FooType>;
};


using Entity_NonAspectual = Bar<Foo>;


template<class FooAspect = Aspect_Foo,
         class BarAspect = Aspect_Bar>
using Entity_Aspectual = typename BarAspect::template BarTrait<
        FooAspect::template FooTrait>;


int main()
{  
  Entity_NonAspectual workingEntity;
  workingEntity.foo();
  workingEntity.bar();
  workingEntity.specialBar();

  Entity_Aspectual<> brokenEntity;

  brokenEntity.foo();
  brokenEntity.bar();
  brokenEntity.specialBar();
}

But in Clang 3.6, I get the following error message when calling brokenEntity.specialBar():

error: no member named 'specialBar' in 'Bar<FooTrait>'

Is this a compiler bug in Clang? Is there a workaround? Currently I'm pretty comfortable in Visual Studio 2013 with LLVM, and getting GCC to work with VS seems like a pain. I'm open to suggestions for alternative Windows-based IDE/compiler combinations as well.

来源:https://stackoverflow.com/questions/31775780/clang-cant-handle-a-template-specialization-using-referenced-template-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!