[英]std::swap with two double variables leads to g++ compiler error
由於未知原因,簡單的 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
...
它也通過編譯utility
修復:
g++ -c -fmodules-ts -x c++-system-header -std=c++20 iostream algorithm numbers string vector cmath list cassert fstream cstddef utility
g++ -fmodules-ts -std=c++20 -lGL -lglut -c \
raytracer/Vector3d.cpp \
...
raytracer/BoundingBox.cpp
...
奇怪的是,在將import <algorithm>
切換為import <utility>
之后,即使我將其切換回 algorithm 或將兩者都刪除,它仍然有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.