我的代码有什么问题?GCC和MSVC认为没问题

JHB*_*ius 6 c++ compiler-errors clang c++20

我正在参与“代码降临”挑战(2021 年第 18 天)。作为一个测试,我尝试在不同的编译器上编译它。虽然 GCC (11.2) 和 MSVC (19.30) 认为这没问题,但 Clang (13.0.0) 会抛出一系列错误。链接到编译器资源管理器

/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c++/11.2.0/bits/alloc_traits.h:514:4: error: no matching function for call to 'construct_at'
          std::construct_at(__p, std::forward<_Args>(__args)...);
          ^~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c++/11.2.0/bits/vector.tcc:115:21: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<RegularNumber>>::construct<RegularNumber, int, Named<int, index_for_vector_of_RegularNumber> &, Named<int, index_for_vector_of_RegularNumber>>' requested here
            _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
                           ^
<source>:115:19: note: in instantiation of function template specialization 'std::vector<RegularNumber>::emplace_back<int, Named<int, index_for_vector_of_RegularNumber> &, Named<int, index_for_vector_of_RegularNumber>>' requested here
        regNumVec.emplace_back(*it - '0', leftRegNumIdx,
                  ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c++/11.2.0/bits/stl_construct.h:94:5: note: candidate template ignored: substitution failure [with _Tp = RegularNumber, _Args = <int, Named<int, index_for_vector_of_RegularNumber> &, Named<int, index_for_vector_of_RegularNumber>>]: no matching constructor for initialization of 'RegularNumber'
    construct_at(_Tp* __location, _Args&&... __args)
    ^
Run Code Online (Sandbox Code Playgroud)

根据其他两个人的说法,Clang 不明白什么?这是一个错误,还是我的错误?

这是“最小化”代码:

/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c++/11.2.0/bits/alloc_traits.h:514:4: error: no matching function for call to 'construct_at'
          std::construct_at(__p, std::forward<_Args>(__args)...);
          ^~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c++/11.2.0/bits/vector.tcc:115:21: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<RegularNumber>>::construct<RegularNumber, int, Named<int, index_for_vector_of_RegularNumber> &, Named<int, index_for_vector_of_RegularNumber>>' requested here
            _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
                           ^
<source>:115:19: note: in instantiation of function template specialization 'std::vector<RegularNumber>::emplace_back<int, Named<int, index_for_vector_of_RegularNumber> &, Named<int, index_for_vector_of_RegularNumber>>' requested here
        regNumVec.emplace_back(*it - '0', leftRegNumIdx,
                  ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c++/11.2.0/bits/stl_construct.h:94:5: note: candidate template ignored: substitution failure [with _Tp = RegularNumber, _Args = <int, Named<int, index_for_vector_of_RegularNumber> &, Named<int, index_for_vector_of_RegularNumber>>]: no matching constructor for initialization of 'RegularNumber'
    construct_at(_Tp* __location, _Args&&... __args)
    ^
Run Code Online (Sandbox Code Playgroud)

BoP*_*BoP 13

你的类型是一个聚合

struct RegularNumber {
    using IndexType = RegNumIndex;

    int value{};
    RegNumIndex leftIdx{}, rightIdx{};
};
Run Code Online (Sandbox Code Playgroud)

哪个construct_at尝试用圆括号初始化

::new(std::declval<void*>()) T(std::declval<Args>()...)

但是,聚合需要{}初始化程序,直到编译器实现P0960 允许从带括号的值列表初始化聚合

而 Clang 还没有出现。C++20 的编译器支持