https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67104
Bug ID: 67104 Summary: Constant expression factory function initializes std::array with static storage duration strangely Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: moritz at klammler dot eu Target Milestone: --- Created attachment 36110 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36110&action=edit Source code to reproduce the problem The following program -- that, to my best knowledge, is valid C++14 -- if compiled with GCC fails at the marked assertion. If compiled with Clang, both assertions hold. #include <array> #include <cassert> namespace /* anonymous */ { constexpr auto make_array(const int val) noexcept { std::array<int, 2> result = { { val, 0 } }; return result; } // Replacing `constexpr` by `const` doesn't change anything. constexpr auto numbers_static = make_array(42); } int main() { const auto numbers_automatic = make_array(42); assert(numbers_automatic[0] == 42); // okay assert(numbers_static[0] == 42); // fails } Attached are the source code, preprocessor output and standard error output when compiling with GCC 5.1.0 using this command: $ g++ -std=c++14 -v -save-temps -Wall -Wextra -Werror -pedantic main.cxx There are no warnings or errors reported by the compiler. This issue has already been discussed on Stack Overflow where I have posted a more complicated example to trigger the behavior. https://stackoverflow.com/questions/31762429/initializing-stdarray-with-static-storage-duration-with-a-parameter-pack-expan The reduced example included in this report is courtesy of Stack Overflow user Columbo who has also tried different versions of GCC that reproduced the behavior.