On Mon, Sep 21, 2026 at 10:26 AM Jonathan Wakely <[email protected]> wrote:
> On Mon, 21 Sept 2026 at 08:21, Tomasz Kaminski <[email protected]> > wrote: > > > > > > > > > > On Sun, Sep 20, 2026 at 12:19 PM Jonathan Wakely <[email protected]> > wrote: > >> > >> On Fri, 18 Sept 2026 at 14:35, Albon Wu (BLOOMBERG/ 731 LEX) > >> <[email protected]> wrote: > >> > > >> > Hi all, > >> > > >> > libstdc++ declares multiple methods on initializer_list as constexpr > >> > unconditionally, but N3471 only added these in C++14, so in C++11 > this is > >> > non-conforming. See > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113782 > >> > > >> > This also covers the private constructor of initializer_list, meaning > it is > >> > no longer a literal type in C++11. Some unrelated tests that used > constexpr > >> > initializer_list implicitly are retargeted to C++14. > >> > > >> > Built and tested on x86_64-pc-linux-gnu. Okay for trunk? > >> > >> Thanks for the patch. My concern with this approach is that it's a > >> breaking change for anybody who is (inadvertently or intentionally) > >> relying on this non-conforming behaviour. The benefit of rejecting the > >> code is minimal - does it actually do any harm? > > > > I do not see anything in C++11 standard that would specify compiler-magic > > thjat cosntruct initializer_list out of braces is not usable at compile > time, > > and I do not see how N3471 changed that. > > > So the private constructor can be constexpr for -std=c++11. > > We still need to decide if we want to change the public members, or > just close the bug as WONTFIX. > I am mostly concerned with empty constructors causing regressions, if we have default initialized initializer_list<int> global variable (or more likely a member of a global variable or being used in member initializer), then we will change from having constant initialization to dynamic initialization. And we may end up with no initialization at all (TUs compiled with GCC17+ will assume that other TUs will emit the initialization code). While this is not an issue if the global if initializer_list itself (zero initialization will create de-facto global constructed object), the more concerning cases are when it is used as part of another object's initialization. In general we make constructors (especially empty/default ones) constexpr when possible, so I think it is better to keep constexpr on initializer_list() constructor. However, I'm not sure what we gain from making the member functions non-constexpr. I am much less concerned with them in above context, as constexpr was very limited in C++11. Major benefit is for detecting non-portability in the code that is used amongst various compliers version, including ones that support C++11 only. Tomasz > > > >> > >> > >> So I would prefer to keep these functions as constexpr for > >> -std=gnu++11 and only change -std=c++11 > >> > >
