This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/67104] Constant expression factory function initializes std::array with static storage duration strangely


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
    }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]