This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/67104] Constant expression factory function initializes std::array with static storage duration strangely
- From: "moritz at klammler dot eu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 03 Aug 2015 17:59:46 +0000
- Subject: [Bug c++/67104] Constant expression factory function initializes std::array with static storage duration strangely
- Auto-submitted: auto-generated
- References: <bug-67104-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67104
--- Comment #3 from Moritz Klammler <moritz at klammler dot eu> ---
Note that the following slightly modified program passes all assertions and
behaves identical when compiled with either GCC or Clang.
#include <array>
#include <cassert>
namespace /* anonymous */
{
constexpr auto
make_array(const int val1, const int val2) noexcept
{
std::array<int, 2> result = { { val1, val2 } };
return result;
}
constexpr auto numbers_static = make_array(42, 0);
}
int
main()
{
const auto numbers_automatic = make_array(42, 0);
assert(numbers_automatic[0] == 42); // okay
assert(numbers_static[0] == 42); // okay
}