Subject: [Boost-bugs] [Boost C++ Libraries] #11670: Boost intrusive constructors should be constexpr
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-09-18 23:15:49
#11670: Boost intrusive constructors should be constexpr
------------------------------+------------------------
Reporter: ben.maurer@⦠| Owner: igaztanaga
Type: Bugs | Status: new
Milestone: To Be Determined | Component: intrusive
Version: Boost 1.60.0 | Severity: Problem
Keywords: |
------------------------------+------------------------
Boost intrusive constructors should be marked constexpr. Doing so would
allow for their use in static variables without SIOF. As an example
consider this program that uses a simple linked list
http://ideone.com/O5YWM8
because the LinkedList constructor is not constexpr, the variable gets
initialized in file declaration order -- after my_crazy_variable.
Therefore even though my_crazy_variable's ctor pushes something on to the
list, it gets lost when the list is initialized and the program crashes
due to being unable to pop a value.
However, if you declare LinkedList's constructor constexpr the list is
initialized in the zero initialization phase
(http://en.cppreference.com/w/cpp/language/initialization#Non-
local_variables). This means that the linked list can be used in other
constructors without worrying about initialization order.
While my example is obviously not a sane use case, imagine a linked list
that registers all live Widget objects. if somebody creates a widget
during static initialization they could encounter the same problem.
A side benefit to doing this is that code size is reduced as the code to
initialize the linked list is not created
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11670> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:19 UTC