对`sTD :: IS_CONSTANT_EVALED()的未定义引用()在C++ 20 GCC中
这只是一个最小可重复的示例:
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;
}
此代码,当用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
相反,如果我直接在Hash Struct中定义模板参数,则 此代码。 ,没有错误!
template<>
struct std::hash<my_class<char>> {
std::size_t operator()(my_class<char> const &s) const noexcept {
return 0;
}
};
我很困惑什么是错误!
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:
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这只是@ildjarn在评论中建议的GCC模块实现中的一些错误。
我能够通过在源代码中添加此行来摆脱错误:
constexpr bool std :: is_constant_evaLED()noexcept;
,但我不确定到底出了什么问题,或者为什么添加此问题解决了错误。
I think it is just some bug in GCC modules implementation as suggested by @ildjarn in comments.
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.