public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/67104] New: Constant expression factory function initializes std::array with static storage duration strangely
@ 2015-08-03 17:48 moritz at klammler dot eu
  2015-08-03 17:49 ` [Bug c++/67104] " moritz at klammler dot eu
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: moritz at klammler dot eu @ 2015-08-03 17:48 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-08-17 18:42 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-03 17:48 [Bug c++/67104] New: Constant expression factory function initializes std::array with static storage duration strangely moritz at klammler dot eu
2015-08-03 17:49 ` [Bug c++/67104] " moritz at klammler dot eu
2015-08-03 17:50 ` moritz at klammler dot eu
2015-08-03 17:59 ` moritz at klammler dot eu
2015-08-03 18:29 ` trippels at gcc dot gnu.org
2015-08-04  8:40 ` [Bug c++/67104] [5/6 regression] " trippels at gcc dot gnu.org
2015-08-07 13:54 ` trippels at gcc dot gnu.org
2015-08-12 18:03 ` jason at gcc dot gnu.org
2015-08-12 18:09 ` jason at gcc dot gnu.org
2015-08-13  7:20 ` trippels at gcc dot gnu.org
2015-08-13  7:32 ` [Bug c++/67104] [5 " trippels at gcc dot gnu.org
2015-08-17 15:45 ` jason at gcc dot gnu.org
2015-08-17 16:06 ` jason at gcc dot gnu.org
2015-08-17 18:42 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).