Error: no member named 'rank_' in 'EndIndex'

I am trying to use the Adept automatic differentiation library, and I did its work with gcc 4.9.0 and icc 16.0.2, but not with VS 2017 and Clang 4.0.1

I reduced the problem to the next snippet, and although I am addressing the problem with the creators of the library, for the sake of knowledge, I would like to know why this piece of code works in the two mentioned compilers and cannot be built in the other two.

template <typename A>
struct Expression
{
  static const int rank = A::rank_;
};

struct EndIndex : public Expression<EndIndex>
{
  static const int rank_ = 0;
};

int  main(int argc, char ** argv)
{
  return 0;
}

Output for VS 2017:

1>------ Build started: Project: Test, Configuration: Debug Win32 ------
1>Source.cpp
1>d:\Test\source.cpp(4): error C2039: 'rank_': is not a member of 'EndIndex'
1>d:\Test\source.cpp(7): note: see declaration of 'EndIndex'
1>d:\Test\source.cpp(8): note: see reference to class template instantiation 'Expression<EndIndex>' being compiled
1>d:\Test\source.cpp(4): error C2065: 'rank_': undeclared identifier
1>d:\Test\source.cpp(4): error C2131: expression did not evaluate to a constant
1>d:\Test\source.cpp(4): note: failure was caused by non-constant arguments or reference to a non-constant symbol
1>d:\Test\source.cpp(4): note: see usage of 'rank_'
1>Done building project "Test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

And the output for Clang 4.0.1:

source.cpp:4:37: error: no member named 'rank_' in 'EndIndex'
                              static const int rank = A::rank_;
                                                      ~~~^
source.cpp:7:38: note: in instantiation of template class 'Expression<EndIndex>' requested here
                                                      struct EndIndex : public Expression<EndIndex>
+4
source share
2 answers

This probably happens because rank_at this stage it is not defined.

The following fixes for Apple LLVM version 9.0.0 (clang-900.0.38):

template <typename A>
struct Expression
{
  static const int rank;
};

struct EndIndex : public Expression<EndIndex>
{
  static const int rank_ = 0;
};

template <typename A>
const int Expression<A>::rank = A::rank_;
+3
source

Visual ++ clang rank_ EndIndex, . .

0

Source: https://habr.com/ru/post/1687709/


All Articles