Why clang++37 behaves differently on 9.3 and 10.3?

Dimitry Andric dim at FreeBSD.org
Thu May 12 18:00:08 UTC 2016

On 12 May 2016, at 13:33, Yuri <yuri at rawbw.com> 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

export CC=clang
export CXX=clang++

cd /usr/src/lib/libcxxrt
make obj
make depend
make install

cd /usr/src/lib/libc++
make obj
make depend
make install

Alternatively, rebuild world with these settings in /etc/src.conf:


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:

    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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.freebsd.org/pipermail/freebsd-ports/attachments/20160512/53190bf8/attachment.sig>

More information about the freebsd-ports mailing list