Date: Thu, 12 May 2016 19:59:43 +0200 From: Dimitry Andric <dim@FreeBSD.org> To: Yuri <yuri@rawbw.com> Cc: "ports@freebsd.org" <ports@freebsd.org> Subject: Re: Why clang++37 behaves differently on 9.3 and 10.3? Message-ID: <C77175B8-972A-4320-AD85-3F82EEC13539@FreeBSD.org> In-Reply-To: <57346A14.6010402@rawbw.com> References: <57346A14.6010402@rawbw.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--Apple-Mail=_C7A2D3F8-C489-4E4F-9046-745DF68D67FB Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii On 12 May 2016, at 13:33, Yuri <yuri@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 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 --Apple-Mail=_C7A2D3F8-C489-4E4F-9046-745DF68D67FB Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.30 iEYEARECAAYFAlc0xJ4ACgkQsF6jCi4glqOMngCg8wS9o9nJZQHyvRhE2nRz52h8 L+IAoOs+3DIozpZksgxUnQBeKZzYeslC =KtQg -----END PGP SIGNATURE----- --Apple-Mail=_C7A2D3F8-C489-4E4F-9046-745DF68D67FB--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?C77175B8-972A-4320-AD85-3F82EEC13539>