3

When I try to run this code in Visual C++ (2015)

template<int V>
struct outer
{
    template<int U, bool>
    struct inner;
};
template<int V>
template<bool B>
struct outer<V>::inner<V, B> { enum { value = 0 }; };

int main()
{
    return outer<1>::inner<1, false>::value;
}

I get the error

Temp.cpp(13): error C2027: use of undefined type 'outer<1>::inner<1,false>'
Temp.cpp(13): note: see declaration of 'outer<1>::inner<1,false>'
Temp.cpp(13): error C2065: 'value': undeclared identifier

However, it compiles and runs fine on GCC and Clang.

Three questions:

  1. If the partial specialization isn't partially specializing, what is it doing?

  2. Why does this happen? Is it a bug, or is there really a problem with this code?

  3. Is there a workaround that lets you still use the inner template class inside the inner template class, or is the only solution to move the template arguments outside?

user541686
  • 205,094
  • 128
  • 528
  • 886

1 Answers1

0

This is a known limitation in the implementation of C++ in Visual C++ 2015 (one of many).

This does work in Visual C++ 2017, so a version upgrade may be necessary.

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56