boost / thread.hpp失败,'clang ++

编程入门 行业动态 更新时间:2024-10-28 10:35:37
boost / thread.hpp失败,'clang ++ -std = c ++ 11 -stdlib = libc ++'(boost/thread.hpp fails with 'clang++ -std=c++11 -stdlib=libc++')

当尝试使用clang + libc ++(C ++ 11模式)编译这一行时:

#include <boost/thread.hpp>

clang发出以下错误:

In file included from test.cpp:1: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread.hpp:13: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/thread.hpp:17: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/pthread/thread_data.hpp:11: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/locks.hpp:18: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/chrono/time_point.hpp:33: /Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:353:49: error: constexpr function never produces a constant expression static BOOST_CHRONO_LIB_CONSTEXPR float lowest() ... ^ /Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:355:21: note: non-constexpr function 'max' cannot be used in a constant expression return -(std::numeric_limits::max) (); ^ /usr/bin/../lib/c++/v1/limits:443:43: note: declared here _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return ... ^ In file included from test.cpp:1: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread.hpp:13: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/thread.hpp:17: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/pthread/thread_data.hpp:11: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/locks.hpp:18: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/chrono/time_point.hpp:33: /Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:361:50: error: constexpr function never produces a constant expression static BOOST_CHRONO_LIB_CONSTEXPR double lowest() ... ^ /Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:363:21: note: non-constexpr function 'max' cannot be used in a constant expression return -(std::numeric_limits::max) (); ^ /usr/bin/../lib/c++/v1/limits:443:43: note: declared here _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return ... ^ In file included from test.cpp:1: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread.hpp:13: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/thread.hpp:17: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/pthread/thread_data.hpp:11: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/locks.hpp:18: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/chrono/time_point.hpp:33: /Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:369:55: error: constexpr function never produces a constant expression static BOOST_CHRONO_LIB_CONSTEXPR long double lowest() ... ^ /Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:371:21: note: non-constexpr function 'max' cannot be used in a constant expression return -(std::numeric_limits::max)(); ^ /usr/bin/../lib/c++/v1/limits:443:43: note: declared here _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return ... ^ 3 errors generated.

在我看来这是libc ++中的一个错误,因为C ++ 11确实要求这些函数是constexpr 。

任何人遇到同样的问题,你能同意吗? 你知道任何修复吗?

我的铿锵版是:

Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn) Target: x86_64-apple-darwin11.4.2 Thread model: posix

When trying to compile this one line with clang + libc++ (C++11 mode):

#include <boost/thread.hpp>

clang emits the following errors:

In file included from test.cpp:1: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread.hpp:13: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/thread.hpp:17: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/pthread/thread_data.hpp:11: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/locks.hpp:18: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/chrono/time_point.hpp:33: /Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:353:49: error: constexpr function never produces a constant expression static BOOST_CHRONO_LIB_CONSTEXPR float lowest() ... ^ /Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:355:21: note: non-constexpr function 'max' cannot be used in a constant expression return -(std::numeric_limits::max) (); ^ /usr/bin/../lib/c++/v1/limits:443:43: note: declared here _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return ... ^ In file included from test.cpp:1: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread.hpp:13: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/thread.hpp:17: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/pthread/thread_data.hpp:11: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/locks.hpp:18: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/chrono/time_point.hpp:33: /Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:361:50: error: constexpr function never produces a constant expression static BOOST_CHRONO_LIB_CONSTEXPR double lowest() ... ^ /Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:363:21: note: non-constexpr function 'max' cannot be used in a constant expression return -(std::numeric_limits::max) (); ^ /usr/bin/../lib/c++/v1/limits:443:43: note: declared here _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return ... ^ In file included from test.cpp:1: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread.hpp:13: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/thread.hpp:17: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/pthread/thread_data.hpp:11: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/locks.hpp:18: In file included from /Users/yongwei/Programming/boost_1_52_0/boost/chrono/time_point.hpp:33: /Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:369:55: error: constexpr function never produces a constant expression static BOOST_CHRONO_LIB_CONSTEXPR long double lowest() ... ^ /Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:371:21: note: non-constexpr function 'max' cannot be used in a constant expression return -(std::numeric_limits::max)(); ^ /usr/bin/../lib/c++/v1/limits:443:43: note: declared here _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return ... ^ 3 errors generated.

It looks to me this is a bug in libc++, because C++11 does require these functions to be constexpr.

Anyone encountered the same problem and can you concur? Do you know about any fixes?

My clang version is:

Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn) Target: x86_64-apple-darwin11.4.2 Thread model: posix

最满意答案

在马克思的暗示下,我找到了一个解决方法。 在这种情况下,定义BOOST_NO_CXX11_NUMERIC_LIMITS帮助。 所以它似乎是libc ++的不完整性。

根据Howard Hinnant的说法,这是一个libc ++的错误,已经修复了主干。 但是,当Apple可以将修复程序发布到Xcode时,还没有任何信息。 我现在将标记回答的问题。

编辑:Apple LLVM版本4.2(clang-425.0.28)(基于LLVM 3.2svn)修复了该问题。 我目前的Xcode版本是4.6.3。

With Marx's hint, I found a workaround. Defining BOOST_NO_CXX11_NUMERIC_LIMITS helps in this case. So it does seem to be an incompleteness of libc++.

According to Howard Hinnant, it is a bug of libc++, and is already fixed on the trunk. However, no info yet when Apple can release the fix into Xcode. I will mark the question answered for now.

EDIT: The issue is fixed in Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn). My current Xcode version is 4.6.3.

更多推荐

本文发布于:2023-08-08 01:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466710.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:thread   boost   clang   hpp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!