On Tue, 1 Feb 2022 at 18:54, Martin Sebor via Libstdc++ <libstd...@gcc.gnu.org> wrote: > > Passing an uninitialized object to a function that takes its argument > by const reference is diagnosed by -Wmaybe-uninitialized because most > such functions read the argument. The exceptions are functions that > don't access the object but instead use its address to compute > a result. This includes a number of std::array member functions such > as std::array<N>::size() which returns the template argument N. Such > functions may be candidates for attribute const which also avoids > the warning. The attribute typically only benefits extern functions > that IPA cannot infer the property from, but in this case it helps > avoid the warning which runs very early on, even without optimization > or inlining. The attached patch adds the attribute to a subset of > those member functions of std::array. (It doesn't add it to const > member functions like cbegin() or front() that return a const_iterator > or const reference to the internal data.) > > It might be possible to infer this property from inline functions > earlier on than during IPA and avoid having to annotate them explicitly. > That seems like an enhancement worth considering in the future. > > Tested on x86_64-linux. > > Martin
new file mode 100644 index 00000000000..b7743adf3c9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/iterators/begin_end.cc @@ -0,0 +1,56 @@ +// { dg-do compile { target c++11 } } +// +// Copyright (C) 2011-2022 Free Software Foundation, Inc. Those dates look wrong. I no longer bother putting a license text and copyright notice on simple tests like this. It's meaningless to assert copyright on something so trivial that doesn't do anything.