MSVC 在转发类模板声明中阻塞

MSVC chokes in forward class template declaration

本文关键字:声明 转发 MSVC      更新时间:2023-10-16

MSVC 编译失败

#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;
}

(3): error C2065: 'N': unknown identifier (10): error C2975: 'V': invalid template argument 'A', constant expression expected(粗略翻译(。

叮当默编译。

那么,问题来了:烂代码还是痴呆的MSVC?

MSVC 版本 = VS 2019

这是 MSVC 中的一个错误,在编译器版本 19.22 之前已经出现,并在 19.23 中修复。演示:https://gcc.godbolt.org/z/occvKEfc3