简体   繁体   English

在 c++20 gcc 中未定义对 `std::is_constant_evaluate()' 的引用

[英]undefined reference to `std::is_constant_evaluated()' in c++20 gcc

This is just a minimal reproducible example:这只是一个最小的可重现示例:

import <unordered_set>;
import <functional>;

template<class c>
class my_class {
};

template<class c>
struct std::hash<my_class<c>> {
    std::size_t operator()(my_class<c> const &s) const noexcept {
        return 0;
    }
};


int main() {
    std::unordered_set<my_class<char>> x;
}

This code, when compiled with g++ -std=c++20 -fmodules-ts test.cpp produces this error:此代码在使用g++ -std=c++20 -fmodules-ts test.cpp时会产生此错误:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\SOURAV~1\AppData\Local\Temp\cclOkCUA.o:test.cpp:(.text$_ZNSt16allocator_traitsISaIPNSt8__detail15_Hash_node_baseEEE10deallocateERS3_PS2_y[_ZNSt16allocator_traitsISaIPNSt8__detail15_Hash_node_baseEEE10deallocateERS3_PS2_y]+0x2d): undefined reference to `std::is_constant_evaluated()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\SOURAV~1\AppData\Local\Temp\cclOkCUA.o:test.cpp:(.text$_ZNSt16allocator_traitsISaINSt8__detail10_Hash_nodeI8my_classIcELb0EEEEE10deallocateERS5_PS4_y[_ZNSt16allocator_traitsISaINSt8__detail10_Hash_nodeI8my_classIcELb0EEEEE10deallocateERS5_PS4_y]+0x2d): undefined reference to `std::is_constant_evaluated()'
collect2.exe: error: ld returned 1 exit status

Instead if I define template argument directly in hash struct, there is no error!相反,如果我直接在哈希结构中定义模板参数,则没有错误!

template<>
struct std::hash<my_class<char>> {
    std::size_t operator()(my_class<char> const &s) const noexcept {
        return 0;
    }
};

I am confused what is the error!我很困惑是什么错误!

I think it is just some bug in GCC modules implementation as suggested by @ildjarn in comments.我认为这只是@ildjarn 在评论中建议的 GCC 模块实现中的一些错误。

I was able to get rid of error by adding this line in the source code:通过在源代码中添加这一行,我能够摆脱错误:
constexpr bool std::is_constant_evaluated() noexcept;

But I'm not sure what exactly was wrong or why did adding this solved the error.但我不确定到底出了什么问题,或者为什么添加它可以解决错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM