Boost logo

Boost :

Subject: Re: [boost] BOOST_NO_CXX11_CONSTEXPR and msvc-14.0
From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2015-07-22 20:08:10


On 21 Jul 2015 at 23:48, Peter Dimov wrote:

> I see that BOOST_NO_CXX11_CONSTEXPR is no longer being defined for
> msvc-14.0. Even the RTM version has spotty support for constexpr though; the
> techniques in my metaprogramming article, for example, don't work.

I turned on constexpr for VS2015 for all my own code to see what
happens.

VS2015 RC couldn't compile my code with constexpr on, but I'm glad to
report that with a bit of minor rejigging of code VS2015 successfully
compiles everything I've got with C++ 11 constexpr enabled.

The minor rejigging was a bit silly. For example, I had a constructor
like this:

class A;

class B : public A
{
  B() = default;
  constexpr B(int) : B() { }
};

... and VS2015 barfed about the B(int) not properly initialising all
base classes, even though it is via a delegation to the defaulted
constructor. The simple fix was:

  constexpr B(int) : A() { }

Another example was this:

template<class T> class Foo
{
  union
  {
    T a;
    std::error_code b;
    std::exception_ptr c;
  }
  int d;
  constexpr Foo() : d(5) { }
};

VS2015 didn't like that the union wasn't being initialised, despite
that clang and GCC were happy with it. I think VS2015 is being
correct here actually, the standard seems pretty clear I should have
been initialising something. I worked around it like this:

template<class T> class Foo
{
  struct constexpr_standin_type { };
  union
  {
    T a;
    std::error_code b;
    std::exception_ptr c;
    constexpr_standin_type standin;
  }
  int d;
  constexpr Foo() : standin(), d(5) { }
};

... and now VS2015 is happy.

All these are minor annoyances really, but until Boost code is
similarly rejigged to fit with VS2015's interpretation of constexpr I
wouldn't enable constexpr by default for 1.59. Straight after release
is the right time I think.

And my hat is off to the Visual Studio team for doing such a great
job with VS2015 which really is a very conforming C++ 11 compiler
now. I'm finally beginning to run into things older GCCs and clangs
won't compile that VS2015 will, and that's *amazing*.

Niall

-- 
ned Productions Limited Consulting
http://www.nedproductions.biz/ 
http://ie.linkedin.com/in/nialldouglas/



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