提问人:user5406764 提问时间:3/19/2023 更新时间:3/19/2023 访问量:74
移动 std::ostringstream 时出现奇怪的 clang c++ ubsan 错误
Strange clang c++ ubsan error when moving std::ostringstream
问:
这可能不是发布此内容的正确论坛,因为它看起来像一个错误,我可能应该向 llvm 团队报告。如果您同意,请告诉我,我会这样做。
这是产生 ubsan 错误的代码,以防万一我错了:
OS = MacOS Ventura
Compiler = Clang 16.0.0 (Manually built LLVM with default options)
重现步骤:
clang++ -fsanitize=undefined main.cpp
./a.out
main.cpp
#include <sstream>
struct MyStruct
{
static MyStruct create() noexcept
{
return MyStruct{};
}
private:
std::ostringstream oss_;
};
int main()
{
MyStruct::create();
}
输出:
~/usr/bin/../include/c++/v1/sstream:730:43: runtime error: member access within address 0x7ff7b265a298 which does not point to an object of type 'std::ostringstream'
0x7ff7b265a298: note: object is of type 'std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char>>'
f7 7f 00 00 40 11 8b 0d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^~~~~~~~~~~~~~~~~~~~~~~
vptr for 'std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char>>'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ~/usr/bin/../include/c++/v1/sstream:730:43 in
~/usr/bin/../include/c++/v1/ostream:198:7: runtime error: cast to virtual base of address 0x7ff7b265a298 which does not point to an object of type 'std::ostream'
0x7ff7b265a298: note: object is of type 'std::__1::basic_ostream<char, std::__1::char_traits<char>>'
f7 7f 00 00 c8 11 8b 0d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^~~~~~~~~~~~~~~~~~~~~~~
vptr for 'std::__1::basic_ostream<char, std::__1::char_traits<char>>'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ~/usr/bin/../include/c++/v1/ostream:198:7 in
~/usr/bin/../include/c++/v1/ostream:198:13: runtime error: member call on address 0x7ff7b265a308 which does not point to an object of type 'std::ios'
0x7ff7b265a298: note: object is base class subobject at offset 112 within object of type 'std::__1::basic_ostream<char, std::__1::char_traits<char>>'
f7 7f 00 00 c8 11 8b 0d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ~/usr/bin/../include/c++/v1/ostream:198:13 in
~/usr/bin/../include/c++/v1/ios:711:15: runtime error: member call on address 0x7ff7b265a308 which does not point to an object of type 'std::ios_base'
0x7ff7b265a298: note: object is base class subobject at offset 112 within object of type 'std::__1::basic_ostream<char, std::__1::char_traits<char>>'
f7 7f 00 00 c8 11 8b 0d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ~/usr/bin/../include/c++/v1/ios:711:15 in
~/usr/bin/../include/c++/v1/ios:712:5: runtime error: member access within address 0x7ff7b265a308 which does not point to an object of type 'std::ios'
0x7ff7b265a298: note: object is base class subobject at offset 112 within object of type 'std::__1::basic_ostream<char, std::__1::char_traits<char>>'
f7 7f 00 00 c8 11 8b 0d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ~/usr/bin/../include/c++/v1/ios:712:5 in
~/usr/bin/../include/c++/v1/ios:713:5: runtime error: member access within address 0x7ff7b265a308 which does not point to an object of type 'std::ios'
0x7ff7b265a298: note: object is base class subobject at offset 112 within object of type 'std::__1::basic_ostream<char, std::__1::char_traits<char>>'
f7 7f 00 00 c8 11 8b 0d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ~/usr/bin/../include/c++/v1/ios:713:5 in
答: 暂无答案
评论