带有两个双精度变量的 std::swap 会导致 g++编译器错误
由于未知的原因,一个简单的 std::swap 会导致编译器错误:
export module BoundingBox;
import Vector3d;
... (custom files)
import <list>;
import <string>;
import <cassert>;
import <numbers>;
import <algorithm>;
import <cstddef>;
using std::swap;
using std::iterator;
using std::list;
using std::string;
using std::numbers::pi;
export class BoundingBox {
void test()
{
double a=1, b=2;
std::swap(a,b);
}
};
...
这会导致编译器错误:
In file included from /usr/include/c++/11.2.0/bits/stl_pair.h:59,
from /usr/include/c++/11.2.0/bits/stl_algobase.h:64,
from /usr/include/c++/11.2.0/bits/char_traits.h:39,
from /usr/include/c++/11.2.0/string:40,
of module /usr/include/c++/11.2.0/string, imported at raytracer/BoundingBox.cpp:8:
/usr/include/c++/11.2.0/bits/move.h: In instantiation of ‘constexpr std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = double; std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > = void]’:
raytracer/BoundingBox.cpp:1503239:18: required from here
/usr/include/c++/11.2.0/bits/move.h:204:19: internal compiler error: in tsubst_copy, at cp/pt.c:16621
204 | _Tp __tmp = _GLIBCXX_MOVE(__a);
| ^~~~~~~~~~~~~
0xe4c988 internal_error(char const*, ...)
???:0
0xe42d02 fancy_abort(char const*, int, char const*)
???:0
0x1140ae0 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
???:0
0x1141098 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
???:0
0x1140f06 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
???:0
0x11f00ff tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
???:0
0x11f049b tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
???:0
0x11f01de tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
???:0
0x11f0174 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
???:0
0x1294a36 instantiate_decl(tree_node*, bool, bool)
???:0
0xfe2243 instantiate_pending_templates(int)
???:0
0xfddab7 c_parse_final_cleanups()
???:0
不幸的是,我无法生成最小的工作示例,因为该错误在我的测试用例中从未发生。然而,我对 C++ 没有经验,也不知道我应该在庞大的代码库中寻找什么。可能是什么原因造成的? 我使用g++ 11.2.0并编译如下:
g++ -c -fmodules-ts -x c++-system-header -std=c++20 iostream algorithm numbers string vector cmath list cassert fstream cstddef
g++ -fmodules-ts -std=c++20 -lGL -lglut -c \
raytracer/Vector3d.cpp \
...
raytracer/BoundingBox.cpp
...
For unknown reasons, a simple std::swap leads to a compiler error:
export module BoundingBox;
import Vector3d;
... (custom files)
import <list>;
import <string>;
import <cassert>;
import <numbers>;
import <algorithm>;
import <cstddef>;
using std::swap;
using std::iterator;
using std::list;
using std::string;
using std::numbers::pi;
export class BoundingBox {
void test()
{
double a=1, b=2;
std::swap(a,b);
}
};
...
This leads to the compiler error:
In file included from /usr/include/c++/11.2.0/bits/stl_pair.h:59,
from /usr/include/c++/11.2.0/bits/stl_algobase.h:64,
from /usr/include/c++/11.2.0/bits/char_traits.h:39,
from /usr/include/c++/11.2.0/string:40,
of module /usr/include/c++/11.2.0/string, imported at raytracer/BoundingBox.cpp:8:
/usr/include/c++/11.2.0/bits/move.h: In instantiation of ‘constexpr std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = double; std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > = void]’:
raytracer/BoundingBox.cpp:1503239:18: required from here
/usr/include/c++/11.2.0/bits/move.h:204:19: internal compiler error: in tsubst_copy, at cp/pt.c:16621
204 | _Tp __tmp = _GLIBCXX_MOVE(__a);
| ^~~~~~~~~~~~~
0xe4c988 internal_error(char const*, ...)
???:0
0xe42d02 fancy_abort(char const*, int, char const*)
???:0
0x1140ae0 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
???:0
0x1141098 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
???:0
0x1140f06 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
???:0
0x11f00ff tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
???:0
0x11f049b tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
???:0
0x11f01de tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
???:0
0x11f0174 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
???:0
0x1294a36 instantiate_decl(tree_node*, bool, bool)
???:0
0xfe2243 instantiate_pending_templates(int)
???:0
0xfddab7 c_parse_final_cleanups()
???:0
Unfortunately, I have not been able to generate a minimum working example, as the error never occurs in my test cases. However I am not experienced with C++ and have no idea on where I should even be looking in the giant codebase. What could be causing this?
I use g++ 11.2.0 and compile as follows:
g++ -c -fmodules-ts -x c++-system-header -std=c++20 iostream algorithm numbers string vector cmath list cassert fstream cstddef
g++ -fmodules-ts -std=c++20 -lGL -lglut -c \
raytracer/Vector3d.cpp \
...
raytracer/BoundingBox.cpp
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它也通过编译
utility
得到了修复:奇怪的是,在将
import
切换为import
后,即使我将其切换回算法或删除两者,它仍然有效。It was fixed by compiling
utility
as well:The strange thing is, after switching out
import <algorithm>
forimport <utility>
, it works even if I switch it back to algorithm or remove both.