From owner-freebsd-ports@FreeBSD.ORG Wed Jul 18 23:34:11 2012 Return-Path: Delivered-To: freebsd-ports@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A479E1065670 for ; Wed, 18 Jul 2012 23:34:11 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from hammer.pct.niksun.com (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 6606C8FC0C for ; Wed, 18 Jul 2012 23:34:11 +0000 (UTC) Message-ID: <500747F2.8010900@FreeBSD.org> Date: Wed, 18 Jul 2012 19:34:10 -0400 From: Jung-uk Kim User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:13.0) Gecko/20120626 Thunderbird/13.0.1 MIME-Version: 1.0 To: freebsd-ports@freebsd.org References: <5006F780.2020004@FreeBSD.org> <44k3y1ndlp.fsf@be-well.ilk.org> <50073701.80205@FreeBSD.org> In-Reply-To: <50073701.80205@FreeBSD.org> X-Enigmail-Version: 1.4.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [FYI] C++ compilers vs. __cplusplus (was Re: SV: Re: make failed for editors/libreoffice) X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Jul 2012 23:34:11 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 While I was tackling LibreOffice build issues, I found something interesting about __cplusplus. Basically, different C++ compilers may have different __cplusplus definitions and it may cause some strangeness. Clang, for example, used to set it to 1 but now it is set to C++ standard value since this commit: http://llvm.org/viewvc/llvm-project?view=rev&revision=156113 This is what I got from head: GCC: % cpp --version cpp (GCC) 4.2.1 20070831 patched [FreeBSD] Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. % cpp -x c++ -dM /dev/null | grep __cplusplus #define __cplusplus 1 % cpp -x c++ -std=gnu++98 -dM /dev/null | grep __cplusplus #define __cplusplus 1 Clang 3.1: % clang-cpp --version FreeBSD clang version 3.1 (branches/release_31 156863) 20120523 Target: x86_64-unknown-freebsd10.0 Thread model: posix % clang-cpp -x c++ -std=c++98 -dM /dev/null | grep __cplusplus #define __cplusplus 199711L % clang-cpp -x c++ -std=c++0x -dM /dev/null | grep __cplusplus #define __cplusplus 201103L % clang-cpp -x c++ -std=gnu++98 -dM /dev/null | grep __cplusplus #define __cplusplus 1 % clang-cpp -x c++ -std=gnu++0x -dM /dev/null | grep __cplusplus #define __cplusplus 1 Clang 3.2 snapshot (ports/lang/clang-devel): % /usr/local/bin/clang++ --version clang version 3.2 (trunk) Target: amd64-portbld-freebsd10.0 Thread model: posix % /usr/local/bin/clang++ -E -x c++ -std=c++98 -dM /dev/null | grep __cplusplus #define __cplusplus 199711L % /usr/local/bin/clang++ -E -x c++ -std=c++0x -dM /dev/null | grep __cplusplus #define __cplusplus 201103L % /usr/local/bin/clang++ -E -x c++ -std=gnu++98 -dM /dev/null | grep __cplusplus #define __cplusplus 199711L % /usr/local/bin/clang++ -E -x c++ -std=gnu++0x -dM /dev/null | grep __cplusplus #define __cplusplus 201103L and so on and so forth... This causes very subtle issues depending on compiler versions and FreeBSD versions. For example, NULL may be defined differently because stable/9 and head have this: #if __cplusplus >= 201103L #define NULL nullptr #elif defined(__GNUG__) && defined(__GNUC__) && __GNUC__ >= 4 #define NULL __null #else #if defined(__LP64__) #define NULL (0L) #else #define NULL 0 #endif /* __LP64__ */ #endif /* __GNUG__ */ Before that, we had this: #if defined(__GNUG__) && defined(__GNUC__) && __GNUC__ >= 4 #define NULL __null #else #if defined(__LP64__) #define NULL (0L) #else #define NULL 0 #endif /* __LP64__ */ #endif /* __GNUG__ */ What a mess... Jung-uk Kim -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAlAHR/IACgkQmlay1b9qnVNd0QCfX1NPpOfc+haRebvmBb1+nMSY KAUAn3A6vKEaV0FQy82gysnV79UdejMf =7G3Z -----END PGP SIGNATURE-----