220 15609 <14072581.09eDfPqFOs@tjmaciei-mobl4> article
Path: news.gmane.org!not-for-mail
From: Thiago Macieira <thiago@macieira.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Library support for relaxed constexpr
Date: Mon, 12 Jan 2015 14:43:32 -0800
Lines: 65
Approved: news@gmane.org
Message-ID: <14072581.09eDfPqFOs@tjmaciei-mobl4>
References: <5ccd3d6e-859c-4b66-b61c-317b704647f2@isocpp.org> <m91euh$u1o$1@ger.gmane.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: ger.gmane.org 1421103253 4353 80.91.229.3 (12 Jan 2015 22:54:13 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 12 Jan 2015 22:54:13 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCB4TK757YBRBD5B2GSQKGQEFIEICQY@isocpp.org Mon Jan 12 23:54:08 2015
Return-path: <std-proposals+bncBCB4TK757YBRBD5B2GSQKGQEFIEICQY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-la0-f72.google.com ([209.85.215.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCB4TK757YBRBD5B2GSQKGQEFIEICQY@isocpp.org>)
	id 1YAns8-0007Cv-Gv
	for gclcip-std-proposals@m.gmane.org; Mon, 12 Jan 2015 23:54:08 +0100
Original-Received: by mail-la0-f72.google.com with SMTP id gq15sf14801119lab.3
        for <gclcip-std-proposals@m.gmane.org>; Mon, 12 Jan 2015 14:54:08 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:to:subject:date:message-id:user-agent
         :in-reply-to:references:mime-version:content-type:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=0CZwPWH8+iwHu/wsKXfdZjlzWz0T2Rz9F/D8ACrR54g=;
        b=l7hqS3rWUtpZRp/thMjGpvhhM6nw2mio+Rhr/i5bVaS7LeJ6gH5l1wGovlK8wtvMIf
         npg4/S+g4Dl+iEtMAph+utEZfg9W28Q/6V3VSWmRtadpIM4EouruytMS4Ppl2KcgWtB6
         IybmA3LECWp2ADqVAWmhAdzd0L5s1yvS4RkV34dP5q+DBouLfAYLuJztNcA33zSRwl+a
         ILTUWYa+mJZN+b/DqilFlbFc9WAH8OdXvkN7KvEr4juGTOgoT35XyMZvVREg/FsAEzLZ
         F3ZTBgZvbo43IAtQyN72a/IVq4RjOWNr2bcqpHQZita7m+WWlthT442iaxZUgJ0oKzg+
         ykNQ==
X-Gm-Message-State: ALoCoQnCl/DZw7wnhMy9hOUnbtPPqGY5vOQRrRPwWPSfye03389QE3mtpCGcxzgwLNKmfMRvDGXl
X-Received: by 10.112.141.232 with SMTP id rr8mr4046508lbb.0.1421103247978;
        Mon, 12 Jan 2015 14:54:07 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.181.13.116 with SMTP id ex20ls694618wid.21.canary; Mon, 12 Jan
 2015 14:54:06 -0800 (PST)
X-Received: by 10.181.12.17 with SMTP id em17mr34769053wid.45.1421103246821;
        Mon, 12 Jan 2015 14:54:06 -0800 (PST)
Original-Received: from gondolin.macieira.info (gondolin.macieira.info. [2a01:4f8:d13:f81:21c:14ff:fe01:12a3])
        by mx.google.com with ESMTP id ei5si16822551wid.4.2015.01.12.14.54.06
        for <std-proposals@isocpp.org>;
        Mon, 12 Jan 2015 14:54:06 -0800 (PST)
Received-SPF: pass (google.com: domain of thiago@macieira.org designates 2a01:4f8:d13:f81:21c:14ff:fe01:12a3 as permitted sender) client-ip=2a01:4f8:d13:f81:21c:14ff:fe01:12a3;
Original-Received: from tjmaciei-mobl4.localnet (jfdmzpr03-ext.jf.intel.com [134.134.139.72])
	by gondolin.macieira.info (Postfix) with ESMTPSA id 47B9C11A770
	for <std-proposals@isocpp.org>; Mon, 12 Jan 2015 14:54:06 -0800 (PST)
User-Agent: KMail/4.14.3 (Linux/3.11.10-21-desktop; KDE/4.14.3; x86_64; ; )
In-Reply-To: <m91euh$u1o$1@ger.gmane.org>
X-Original-Sender: thiago@macieira.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of thiago@macieira.org designates 2a01:4f8:d13:f81:21c:14ff:fe01:12a3
 as permitted sender) smtp.mail=thiago@macieira.org
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:15609
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/15609>

On Monday 12 January 2015 16:39:29 Matthew Woehlke wrote:
> On 2015-01-12 15:56, rhalbersma@gmail.com wrote:
> > [...] it is perhaps time to introduce this feature
> > into the Standard Library.
> > 
> > I write "introduce" rather than "update" because AFAICS, there is
> > currently
> > *zero* usage of relaxed constexpr (e.g. non-const but constexpr member
> > functions) in the current Draft Standard.
> 
> Some implementations have apparently started adding constexpr anyway.
> 
> If a concerted effort is made to 'fix' this, please don't forget places
> like <limits>, <cmath>, etc. (I had to change some code that was
> originally written against libstdc++ because libc++ does not have
> constexpr of e.g. ldexp. Having constexpr of basic math functions and
> number manipulation functions seems like a no-brainer...)

Note that the difference is whether the intrinsic functions are considered 
constexpr or not. For GCC, __builtin_ldexp is constexpr but isn't for Clang:

$ cat test.cpp
constexpr int f() { return __builtin_ldexp(1, 2); }

$ gcc -c test.cpp

$ clang -c test.cpp
test.cpp:1:15: error: constexpr function never produces a constant expression 
[-Winvalid-constexpr]
constexpr int f() { return __builtin_ldexp(1, 2); }
              ^
test.cpp:1:28: note: subexpression not valid in a constant expression
constexpr int f() { return __builtin_ldexp(1, 2); }
                           ^

libstdc++ is written specifically for GCC, so it makes use of that fact.
  template<typename _Tp>
    inline _GLIBCXX_CONSTEXPR
    typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
                                    double>::__type
    ldexp(_Tp __x, int __exp)
    { return __builtin_ldexp(__x, __exp); }

Not so with libc++, which supports multiple compilers and thus doesn't use the 
intrinsic but instead calls the libm function:

template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_integral<_A1>::value, double>::type
ldexp(_A1 __x, int __e) _NOEXCEPT {return ldexp((double)__x, __e);}

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.
