On 12 May 2016, at 13:33, Yuri <[email protected]> wrote: > > clang++37 compiles this simple program fine on 10.3, but fails on 9.3. > > Why does it behave differently on different OS versions? > > It looks like it ignores -std=c++11 on 9.3.
You cannot compile for C++11 on a 9.x installation, because clang will
use libstdc++ by default there, and the version of libstdc++ in the
9.x base system is not C++11 compatible.
To be able to use C++11, you must install libc++ first, using for
example:
export CC=clang
export CXX=clang++
cd /usr/src/lib/libcxxrt
make obj
make depend
make
make install
cd /usr/src/lib/libc++
make obj
make depend
make
make install
Alternatively, rebuild world with these settings in /etc/src.conf:
WITH_CLANG_IS_CC=y
WITH_LIBCPLUSPLUS=y
On FreeBSD 10.x, clang and libc++ are the defaults, and C++11 can be
used out of the box.
> test.cc:6:17: note: initializer of 'vmax' is not a constant expression
> test.cc:5:13: note: declared here
> const int vmax = std::numeric_limits<int>::max();
> ^
This is because libstdc++ defines numeric_limits<int>::max() as follows:
template<>
struct numeric_limits<int>
{
...
static int max() throw()
{ return __INT_MAX__; }
While max() appears to be pretty constant in its return value, it is not
defined constexpr, and therefore you cannot use it in a static assert.
Note that later versions of libstdc++ do use constexpr when appropriate:
https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=166171
-Dimitry
signature.asc
Description: Message signed with OpenPGP using GPGMail
