Posted Mar 6, 2013 12:22 UTC (Wed) by jwakely
In reply to: MSVC
Parent article: Michaelsen: One
You still don't know what you're talking about. I don't care about user-defined literals but constexpr is very important. Do you consider solving the static initialization order fiasco to be unimportant?
A constexpr constructor ensures a global object is guaranteed to be initialized during the static initialization phase, i.e. before any code starts running, so code that runs before main() can be guaranteed the object will be valid, even across different translation units where the order of initialization is not defined. This is useful e.g. for a global std::mutex that is accessed by different translation units. That doesn't work with MSVC because its std::mutex is not only non-constexpr but it allocates memory in its default constructor.
> Ditto for constexprs - they can already be optimized by the compiler and you'd be hard-pressed to do anything complex in 512 level recursion limit. I've only seen constepxrs in practice used for template brainfskery magic.
There is no problem with instantiation depth, not even any templates involved. "Can be optimized by the compiler" is not the same as "guaranteed to be optimized by the compiler" ... but you need a decent C++11 compiler to actually get that guarantee of course.
to post comments)