Boost logo

Boost :

Subject: Re: [boost] enabling constexpr with Visual studio 2015 Update 3 (RC)
From: Billy O'Neal (VC LIBS) (bion_at_[hidden])
Date: 2016-06-23 13:56:53


>I think it may even be a C++17 feature and I have tried /std:c++14 and /std:c++latest to try to enable this.

Extended constexpr was a C++14 feature. /std:c++14 and /std:c++latest don't turn this on because C1XX does not have support for it. We implement only C++11 constexpr at this time, which means constexpr functions must be of the form "return expression;".

Billy3
________________________________
From: Boost <boost-bounces_at_[hidden]> on behalf of Paul A. Bristow <pbristow_at_[hidden]>
Sent: Thursday, June 23, 2016 8:46:30 AM
To: boost_at_[hidden]
Subject: Re: [boost] enabling constexpr with Visual studio 2015 Update 3 (RC)

> -----Original Message-----
> From: Boost [mailto:boost-bounces_at_[hidden]] On Behalf Of Billy O'Neal (VC LIBS)
> Sent: 23 June 2016 15:29
> To: boost_at_[hidden]; boost_at_[hidden]
> Subject: Re: [boost] enabling constexpr with Visual studio 2015 Update 3 (RC)
>
> That is C++14 constexpr; C1XX only supports C++11 constexpr.

I think it may even be a C++17 feature and I have tried /std:c++14 and /std:c++latest to try to enable this.

https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fen.cppreference.com%2fw%2fcpp%2flanguage%2fconstexpr&data=01%7c01%7cbion%40microsoft.com%7ca35d14a8cc9b416013fd08d39b7d9c7d%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=z1Qv6kRkG8d7dCFKX4Q8DwB2a4wI3S6w9pftYjeDZdI%3d says

the function body must be either deleted or defaulted

* or contain any statements except:*

an asm declaration. Not this
a goto statement. No goto.
a statement with a label other than case and default. NO labels.
a try-block . No trying.
a definition of a variable of non-literal type. Is literal (int, float ...)
a definition of a variable of static or thread storage duration. No static.
a definition of a variable for which no initialization is performed. (variable IS initialized)

But maybe the language lawyers can advise if I am mistaken.

either way, it's a showstopper for taking existing code and making constexpr functions.

But there are more hurdles:
template<typename FloatingPointType>
...
BOOST_CONSTEXPR_OR_CONST bool is_neg = (f < FloatingPointType(0));

and

// Extract the mantissa and exponent.
      int exp2 = 0; // Initialize to make constexpr possible.
      BOOST_CONSTEXPR_OR_CONST FloatingPointType fp(frexp((!is_neg) ? f : -f, &exp2));

both fail to compile on VS 2015 update 3 RC and GCC 5.8.0.

So there are hoops that look out of reach for now.

Paul

> On Thu, Jun 23, 2016 at 7:23 AM -0700, "Paul A. Bristow" <pbristow_at_[hidden]<mailto:pbristow_at_[hidden]>>
> wrote:
>
> > -----Original Message-----
> > From: Boost [mailto:boost-bounces_at_[hidden]] On Behalf Of Beman Dawes
> > Sent: 11 June 2016 17:06
> > To: Boost Developers List
> > Subject: Re: [boost] enabling constexpr with Visual studio 2015 Update 3 (RC)
> >
> > You might want to read the thread "[config] Changes needed for VC++ 2015
> > Update 3?" if you have not already done so.
> >
> > Please file a MSVC bug report if you hit any C++11 constexpr bugs in the
> > Update 3 RC. They giving very high priority to C++11 bugs affecting Boost
> > code. They would like us to be able to turn BOOST_NO_CXX11_CONSTEXPR off
> > for Update 3.
>
> Unless I am doing something very silly using VS 2015 Update 3 RC,
> it is not possible to declare and initialization any constexpr intermediate variables within a constexpr function.
>
> constexpr int tripled(int n)
> {
> constexpr int f = 3; // C3250: 'f': declaration is not allowed in 'constexpr' function body
> // constexpr_variable_in_function.cpp(35) : error C3249 : illegal statement or sub - expression for 'constexpr' function
>
> return n * f;
> }
> even using /std:c++latest
>
> Reported as
>
> https://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fconnect.microsoft.com%2fVisualStudio%2ffeedback%
> 2fdetails%2f2849367&data=01%7c01%7cbion%40microsoft.com%7cff91fe2ba4ea4628db3908d39b71f2e8%7c72f988bf86f1
> 41af91ab2d7cd011db47%7c1&sdata=s%2fuVgTFXoqGoAfgDEOSv%2bgo5ZkyDQ%2b03m8B6of9icHw%3d
>
> My reading of C++17 draft is that is now an added feature, and this work with GCC 5.3.0 (not even the most recent
> version).
>
> Lack of this is a showstopper when trying to define any (mathy) function where it is impossible/impractical to provide a
> single
> return statement.
>
> Paul
>
> ---
> Paul A. Bristow
> Prizet Farmhouse
> Kendal UK LA8 8AB
> +44 (0) 1539 561830
>
>
>
>
>
>
> _______________________________________________
> Unsubscribe & other changes:
> https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2flists.boost.org%2fmailman%2flistinfo.cgi%2fboost&dat
> a=01%7c01%7cbion%40microsoft.com%7cff91fe2ba4ea4628db3908d39b71f2e8%7c72f988bf86f141af91ab2d7cd011db47%
> 7c1&sdata=immCBtMvwc7pb3rBkSnywDK4BntAtJrgyEI0MjjAaHU%3d
>
> _______________________________________________
> Unsubscribe & other changes: https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2flists.boost.org%2fmailman%2flistinfo.cgi%2fboost&data=01%7c01%7cbion%40microsoft.com%7ca35d14a8cc9b416013fd08d39b7d9c7d%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=BCapNXGMBjAshlWPQhNBG%2bRh9nZ7y0sZarQrrLI7nHo%3d

_______________________________________________
Unsubscribe & other changes: https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2flists.boost.org%2fmailman%2flistinfo.cgi%2fboost&data=01%7c01%7cbion%40microsoft.com%7ca35d14a8cc9b416013fd08d39b7d9c7d%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=BCapNXGMBjAshlWPQhNBG%2bRh9nZ7y0sZarQrrLI7nHo%3d


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk