public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105407] New: std::construct_at during constant evaluation does not zero-initialize
@ 2022-04-27 13:48 fchelnokov at gmail dot com
  2022-04-27 14:08 ` [Bug c++/105407] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: fchelnokov at gmail dot com @ 2022-04-27 13:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105407
           Summary: std::construct_at during constant evaluation does not
                    zero-initialize
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This example program:
```
#include <memory>
#include <iostream>

struct A {
    int x = x;
};

constexpr int foo() {
    A a{1};
    std::construct_at<A>(&a);
    return a.x;
}

int main() {
    constexpr int v = foo();
    std::cout << v << foo();
}
```
shall print "00" (as Clang and MSVC do), because before "x=x" std::construct_at
must zero-initialize (a), see https://eel.is/c++draft/dcl.init#general-9.1.2

GCC prints "10" (demo: https://gcc.godbolt.org/z/eoEr5KMjM) meaning that it
behaves correctly in run-time, but not during constant evaluation.

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

* [Bug c++/105407] std::construct_at during constant evaluation does not zero-initialize
  2022-04-27 13:48 [Bug c++/105407] New: std::construct_at during constant evaluation does not zero-initialize fchelnokov at gmail dot com
@ 2022-04-27 14:08 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2022-04-27 14:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't think the zero-init makes x=x OK though.

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

end of thread, other threads:[~2022-04-27 14:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27 13:48 [Bug c++/105407] New: std::construct_at during constant evaluation does not zero-initialize fchelnokov at gmail dot com
2022-04-27 14:08 ` [Bug c++/105407] " redi 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).