为什么包括< regex>原因SQRT(负数)抛出域异常
我有一个程序,该程序定期接受负数的std :: sqrt(),并根据需要检查NAN。
使用GCC 6.3.0(在嵌入式平台上),如果我
#include <regex>
在同一库中,而不是返回NAN,则会引发异常。
当使用GCC 8.1(在Windows)和Clang(在Mac中)构建时,相同的代码
在调用所有其他标题之前尝试明确设置
#define math_errhandling MATH_ERRNO
,并且似乎没有效果。
更新:
我将其跟踪到__errno()是这里的实际问题。我发现在第三方库中有一份声明:
int __errno = 0;
如果称为功能,这显然会导致SEG错误。
目前尚不清楚为什么包括Regex将其链接到此库,但删除此问题可以解决问题。
I have a program that regularly takes the std::sqrt() of negative numbers and checks for NaN as required.
Using gcc 6.3.0 (on an embedded platform), if I
#include <regex>
in the same library, instead of returning NaN it will throw an exception.
The same code runs correctly when built using GCC 8.1 (in Windows) and Clang (in Mac)
I tried explicitly setting
#define math_errhandling MATH_ERRNO
before calling all my other headers and it doesn't seem to have an effect.
Update:
I tracked this down to __errno() being the actual problem here. I found that in a 3rd party library there was a declaration:
int __errno = 0;
Which will clearly cause a seg fault if called as a function.
It’s still not clear why including regex caused it to link to this library, but removing this fixes the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论