当尝试使用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: posixWhen 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.
更多推荐
发布评论