From owner-freebsd-current@FreeBSD.ORG Wed Jan 29 16:41:40 2014 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 39DDF943 for ; Wed, 29 Jan 2014 16:41:40 +0000 (UTC) Received: from smtpout6.timeweb.ru (smtpout6.timeweb.ru [92.53.117.39]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E65B31E07 for ; Wed, 29 Jan 2014 16:41:39 +0000 (UTC) Received: from [213.148.20.85] (helo=hive.panopticon) by smtp.timeweb.ru with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1W8YCn-0004x7-2j for freebsd-current@FreeBSD.org; Wed, 29 Jan 2014 20:41:37 +0400 Received: from hades.panopticon (hades.panopticon [192.168.0.32]) by hive.panopticon (Postfix) with ESMTP id 9AE20803 for ; Wed, 29 Jan 2014 20:41:36 +0400 (MSK) Received: by hades.panopticon (Postfix, from userid 1000) id 885751CED6; Wed, 29 Jan 2014 20:41:36 +0400 (MSK) Date: Wed, 29 Jan 2014 20:41:36 +0400 From: Dmitry Marakasov To: freebsd-current@FreeBSD.org Subject: libm lacks C99 functions -> no c++11 cmath in libstdc++ Message-ID: <20140129164136.GA3489@hades.panopticon> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/1.5.22 (2013-10-16) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Jan 2014 16:41:40 -0000 Hi! Gerald haven't responded yet, so I though I'd better post in on the list as well for wider discussion. In short: - our libm lacks some C99 functions: erfl erfcl lgammal tgammal - bad enough by itself, it affects libstdc++ from ports' gcc in such a way that it disables C++11 math completely (along with a lot more other more widely used math functions) - we may probably implement these by calling less-precise erf erfc lgamma tgamma as we do with other functions as we alredy do with some others ----- Forwarded message from Dmitry Marakasov ----- Date: Tue, 21 Jan 2014 19:13:07 +0400 From: Dmitry Marakasov To: gerald@FreeBSD.org Subject: libstdc++ from ports' gcc's and cmath Hi! I've was just curious why one of my ports doesn't build on < 10.x and found the following: This code: --- #include int main() { std::hypot(3.0, 4.0); } --- won't build even with latest gcc: --- % g++49 -std=c++11 2.cc 2.cc: In function 'int main()': 2.cc:2:14: error: 'hypot' is not a member of 'std' int main() { std::hypot(3.0, 4.0); } ^ 2.cc:2:14: note: suggested alternative: In file included from /usr/local/lib/gcc49/include/c++/cmath:44:0, from 2.cc:1: /usr/include/math.h:276:8: note: 'hypot' double hypot(double, double); ^ --- Why's std::hypot not defined? --- /usr/local/lib/gcc49/include/c++/cmath ... #ifdef _GLIBCXX_USE_C99_MATH_TR1 ... namespace std _GLIBCXX_VISIBILITY(default) { ... constexpr float hypot(float __x, float __y) { return __builtin_hypotf(__x, __y); } constexpr long double hypot(long double __x, long double __y) { return __builtin_hypotl(__x, __y); } template constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type hypot(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; return hypot(__type(__x), __type(__y)); } --- As you can see, it's hidden under _GLIBCXX_USE_C99_MATH_TR1. What if I define _GLIBCXX_USE_C99_MATH_TR1? --- % g++49 -std=c++11 2.cc In file included from 2.cc:1:0: /usr/local/lib/gcc49/include/c++/cmath:1064:11: error: '::erfl' has not been declared using ::erfl; ^ /usr/local/lib/gcc49/include/c++/cmath:1068:11: error: '::erfcl' has not been declared using ::erfcl; ^ /usr/local/lib/gcc49/include/c++/cmath:1104:11: error: '::lgammal' has not been declared using ::lgammal; ^ /usr/local/lib/gcc49/include/c++/cmath:1176:11: error: '::tgammal' has not been declared using ::tgammal; ^ --- That's the very reason _GLIBCXX_USE_C99_MATH_TR1 is not defined: libstdc++ configure checks for availability of all C99 math functions in our math library, doesn't find these four and disable whole C99 math set. libstdc++ works this around by using lower-precision variants (e.g. erf instead of erfl) and issues a warning on linking. So I wonder: could libstdc++ be made more usable for C++11 code in some way? That's crucial for pre-clang FreeBSD branches which will live for quite some time, and this is useful for gcc users on post-clang world. The simple solution would be to disable named 4 functions, but make all others available. The better would be to do what libc++ does, with corresponding warnings. What do you think? -- Dmitry Marakasov . 55B5 0596 FF1E 8D84 5F56 9510 D35A 80DD F9D2 F77D amdmi3@amdmi3.ru ..: jabber: amdmi3@jabber.ru http://www.amdmi3.ru ----- End forwarded message ----- -- Dmitry Marakasov . 55B5 0596 FF1E 8D84 5F56 9510 D35A 80DD F9D2 F77D amdmi3@amdmi3.ru ..: jabber: amdmi3@jabber.ru http://www.amdmi3.ru