public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "emmanuel.le-trong@cnrs-orleans.fr" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values
Date: Wed, 09 Dec 2020 15:43:15 +0000	[thread overview]
Message-ID: <bug-98216-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216

            Bug ID: 98216
           Summary: [C++20] std::array<double, N> template parameter error
                    with negative values
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: emmanuel.le-trong@cnrs-orleans.fr
  Target Milestone: ---

Sorry for the bad title, I can't figure out how to summarize this:

    #include <array>
    #include <cassert>

        using
    an_array = std::array <double, 1>;

        constexpr auto
    add_array (an_array a, an_array const& b)
    {
        a[0] += b[0];
        return a;
    }

        template <an_array A>
        struct
    wrapper
    {
            static constexpr auto
        arr = A;
    };


        template <an_array A1 ,an_array A2 >
        auto
    add (wrapper <A1> const&, wrapper <A2> const&)
    {
        return wrapper <add_array (A1, A2)> {};
    }

    constexpr auto ONE       = an_array {{  1. }};
    constexpr auto MINUS_ONE = an_array {{ -1. }}; 
    constexpr auto MINUS_TWO = an_array {{ -2. }}; 

        int
    main ()
    {
        auto a = wrapper <MINUS_TWO> {};
        auto b = wrapper <ONE> {};
        auto c = add (a, b);
        assert (c.arr == MINUS_TWO); // <- should fail
        assert (c.arr == MINUS_ONE); // <- should pass
    }

Compiled with version 11.0.0 20201209, the first assertion passes and the
second fails. It should be the opposite.

FWIW, if you replace double by float, it works as intended.

             reply	other threads:[~2020-12-09 15:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-09 15:43 emmanuel.le-trong@cnrs-orleans.fr [this message]
2020-12-09 16:04 ` [Bug c++/98216] " redi at gcc dot gnu.org
2020-12-10  7:33 ` rguenth at gcc dot gnu.org
2020-12-10 17:05 ` redi at gcc dot gnu.org
2020-12-10 17:16 ` redi at gcc dot gnu.org
2020-12-10 17:56 ` emmanuel.le-trong@cnrs-orleans.fr
2020-12-14 20:56 ` ppalka at gcc dot gnu.org
2021-07-27  8:08 ` [Bug c++/98216] [C++20] template mangling for double template argument is wrong pinskia at gcc dot gnu.org
2021-09-23 18:57 ` ppalka at gcc dot gnu.org
2021-09-23 19:01 ` ppalka at gcc dot gnu.org
2021-09-24 16:36 ` cvs-commit at gcc dot gnu.org
2021-09-24 19:36 ` emmanuel.le-trong@cnrs-orleans.fr
2021-10-06 14:15 ` cvs-commit at gcc dot gnu.org
2021-10-14 19:06 ` hq.ks at web dot de
2021-10-14 21:39 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-98216-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).