非类型模板参数类型随机变化

Non-type template parameter type changes randomly

我不确定这是否是一个编译器错误,或者我是否做了一些违反标准的事情导致未定义的行为。这是我的代码:

#include <iostream>
template<auto InputSize, typename SizeType = decltype(InputSize)>
class StaticArray
{
public:
    using size_type = SizeType;
    using size_type2 = decltype(InputSize);
};

int main()
{
    //StaticArray<2, int> s1;
    StaticArray<2ull, int> s3;
    std::cout << typeid(decltype(s3)::size_type).name() << "\t" << typeid(decltype(s3)::size_type2).name() << "\n";
    return 0;
}

如果注释掉的行保持注释掉,我得到正确的输出:int unsigned __int64。但是,如果我取消注释该行,我会得到输出 int int。作为参考,我正在 MSVC 2017 v15.9.2 上的 x86 调试中编译它。

这看起来像是一个编译器错误,请参阅 https://godbolt.org/z/k2ng-1。如果 MSVC 的版本小于或等于 19.16,它就会出现你显示的问题,从 19.20 开始一切正常。

编辑:测试代码下方应该 link 将来中断:

#include <type_traits>

template<auto InputSize, typename SizeType = decltype(InputSize)>
class StaticArray
{
public:
    using size_type = SizeType;
    using size_type2 = decltype(InputSize);
};

int main()
{
    StaticArray<2, int> s1;
    StaticArray<2ull, int> s3;

    static_assert(std::is_same_v<decltype(s3)::size_type, int>, "ERROR 1");
    static_assert(std::is_same_v<decltype(s3)::size_type2, unsigned long long>, "ERROR 2");
}