Nazinho
Nazinho

Reputation: 321

MSVC chokes in forward class template declaration

MSVC fails to compile

#include <iostream>

template<int N, int = N>
struct A;

template<int, int V>
struct A{static constexpr int VALUE = V;};

int main() {
  A<1> a;
  std::cout << a.VALUE;
}

with (3): error C2065: 'N': unknown identifier (10): error C2975: 'V': invalid template argument 'A', constant expression expected (roughly translated).

clang compiles it silently.

So, the question: rotten code or demented MSVC?

MSVC version = VS 2019.

Upvotes: 7

Views: 93

Answers (1)

Fedor
Fedor

Reputation: 21201

It was a bug in MSVC manifested up to compiler version 19.22, and fixed in 19.23. Demo: https://gcc.godbolt.org/z/occvKEfc3

Upvotes: 1

Related Questions