public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101777] New: Copying array of non-trivial type during constant evaluation is incorrect
@ 2021-08-04 16:31 davidfromonline at gmail dot com
  2021-08-04 16:35 ` [Bug c++/101777] " pinskia at gcc dot gnu.org
  2022-07-03 21:47 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: davidfromonline at gmail dot com @ 2021-08-04 16:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101777
           Summary: Copying array of non-trivial type during constant
                    evaluation is incorrect
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davidfromonline at gmail dot com
  Target Milestone: ---

The following well-formed translation unit

```
struct value {
        constexpr value():
                m_value(new int())
        {
        }

        constexpr value(value const &):
                m_value(new int())
        {
        }

        value(value &&) = delete;
        void operator=(value const &) = delete;
        void operator=(value &&) = delete;

        constexpr ~value() {
                delete m_value;
        }

private:
        int * m_value;
};

struct array {
        value m[1];
};

constexpr bool test() {
        auto a = array();
        auto b = a;
        return true;
}

static_assert(test());
```

Fails with the message

```
<source>:34:19: error: non-constant condition for static assertion
   34 | static_assert(test());
      |               ~~~~^~
<source>:34:19:   in 'constexpr' expansion of 'test()'
<source>:32:1:   in 'constexpr' expansion of '(& b)->array::~array()'
<source>:24:8:   in 'constexpr' expansion of '<anonymous>->value::~value()'
<source>:17:24: error: deallocation of already deallocated storage
   17 |                 delete m_value;
      |                        ^~~~~~~
Compiler returned: 1
```

Compiler explorer: https://godbolt.org/z/bcWf3sr4f

I suspect this is another case where some part of the constant evaluation
assumes an operation is trivial even though it is not (assuming copying array
members is trivial would cause this issue).

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

* [Bug c++/101777] Copying array of non-trivial type during constant evaluation is incorrect
  2021-08-04 16:31 [Bug c++/101777] New: Copying array of non-trivial type during constant evaluation is incorrect davidfromonline at gmail dot com
@ 2021-08-04 16:35 ` pinskia at gcc dot gnu.org
  2022-07-03 21:47 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-04 16:35 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-08-04

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/101777] Copying array of non-trivial type during constant evaluation is incorrect
  2021-08-04 16:31 [Bug c++/101777] New: Copying array of non-trivial type during constant evaluation is incorrect davidfromonline at gmail dot com
  2021-08-04 16:35 ` [Bug c++/101777] " pinskia at gcc dot gnu.org
@ 2022-07-03 21:47 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-07-03 21:47 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |janpmoeller at gmx dot de

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 106174 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2022-07-03 21:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-04 16:31 [Bug c++/101777] New: Copying array of non-trivial type during constant evaluation is incorrect davidfromonline at gmail dot com
2021-08-04 16:35 ` [Bug c++/101777] " pinskia at gcc dot gnu.org
2022-07-03 21:47 ` pinskia 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).