constexpr Complete For VS 2015 RTM: C++11 compiler, C++17 STL

We’ve finished implementing constexpr for VS 2015 RTM, and we’ve updated the online compiler at webcompiler.cloudapp.net with our latest development build.

   

As I previously mentioned, the compiler currently supports C++11’s original rules for constexpr.  C++14 extended constexpr will be implemented in the future, but not in 2015 RTM.

   

In the STL, we’ve implemented every occurrence of constexpr in the current C++17 Working Paper N4527, with a very small number of exceptions:

 

  • min()/max()/minmax() for initializer_list (requires compiler support for C++14 extended constexpr)
  • min_element()/max_element()/minmax_element() (same reason)
  • numeric_limits<float/double/long double>::quiet_NaN()/signaling_NaN() (requires compiler magic, as far as I can tell)
  • mutex’s default constructor (needs to be significantly overhauled after we can drop support for XP targeting)
  • error_category’s default constructor (in an earlier fix I used reinterpret_cast, which is incompatible with constexpr; I can easily change that, but not between RC and RTM)

 

And by “implemented”, I mean that I’ve got a test case that exercises every occurrence of constexpr in the STL, which the compiler accepts without any workarounds.  All the tricky stuff works, like bitset’s constructor from unsigned long long and tuple’s converting move constructor.

   

Of course, there are still some bugs lurking, especially given the magnitude of this feature.  So, we’d like to invite you to try out the online compiler and report any issues you find.  (And report them soon, like this week.)  I’m not aware of any constexpr bugs in the STL, but there are a few compiler bugs that remain to be fixed – notably DevDiv#1134662 “constexpr constructors are emitting dynamic initializers” and 1165072 “constexpr ICE with brace elision” in our internal database.

   

Microsoft Connect is the official place to report bugs, but we’ll accept constexpr bug reports in VCBlog comments here.

   

Finally, credits: this was made possible by Tanveer Gani’s herculean work in the compiler, with /analyze fixes contributed by Dave Bartolomeo.  The STL was constexpr-ized by P.J. Plauger of Dinkumware and myself, with <limits> changes contributed by Alex Voicu.

   

Stephan T. Lavavej

Senior Developer – Visual C++ Libraries

stl@microsoft.com