Clang++-3.7 CRTP compilation error “no named member” in parent's template argument

梦想与她 提交于 2019-12-10 14:59:35

问题


In the below code I am trying to use CRTP to use the static member "value" from the Child class in the Parent class. When compiling the code with g++ 5.2.1 with the "-pedantic" flag, I am able to compile as expected, and on execution both c.print_value(); and Child<int,4>::print_value(); print out 4.

#include <iostream>

template <typename DE>
struct Parent
{
    static const int value = DE::value;
    static void print_value ()
    {
        std::cout << "Value : " << value << '\n';
    }
};

template <typename T, int N>
struct Child : Parent< Child<T,N> >
{
    static const int value = N;
};

int
main ()
{
    Child<int,4> c;
    c.print_value();
    Child<int,4>::print_value();
}

However when compiling the same code with clang++3.7, I encounter compilation failures.

crtp_clang_error.cpp:9:32: error: no member named 'value' in 'Child<int, 4>'
static const int value = DE::value;
                       ~~~~^
crtp_clang_error.cpp:27:16: note: in instantiation of template class 'Parent<Child<int, 4> >' requested here
struct Child : Parent< Child<T,N> >
           ^
crtp_clang_error.cpp:38:16: note: in instantiation of template class 'Child<int, 4>' requested here
  Child<int,4> c;
           ^
crtp_clang_error.cpp:40:3: error: no member named 'print_value' in 'Child<int, 4>'; did you mean 'Parent<Child<int, 4> >::print_value'?
  Child<int,4>::print_value();
  ^~~~~~~~~~~~~~~~~~~~~~~~~
  Parent<Child<int, 4> >::print_value
crtp_clang_error.cpp:11:15: note: 'Parent<Child<int, 4> >::print_value' declared here
  static void print_value ()

I am not sure if this a Clang++ bug or a GCC hack. Would very much appreciate some insights.

来源:https://stackoverflow.com/questions/35759047/clang-3-7-crtp-compilation-error-no-named-member-in-parents-template-argume

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