public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107206] New: Bogus -Wuninitialized in std::optional
@ 2022-10-10 23:14 ed at catmur dot uk
  2022-10-11  8:16 ` [Bug libstdc++/107206] " rguenth at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: ed at catmur dot uk @ 2022-10-10 23:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107206
           Summary: Bogus -Wuninitialized in std::optional
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ed at catmur dot uk
  Target Milestone: ---

Since 12, at -std=c++17 -O -Wuninitialized:

#include <optional>
struct X {
    X() = default;
    X(X const& r) : i(r.i) {}
    int i;
};
struct Y {
    Y() : x() {}
    X x;
    std::optional<int> o;
};
struct Z {
    Y y;
    explicit Z(Y y) : y(y) {}
};
void f(Y const&);
void test() {
    Y const y;
    Z z(y);
    z.y.o = 1;
    auto const w = z;
    f(w.y);
}

In copy constructor 'Y::Y(const Y&)',
    inlined from 'void test()' at <source>:19:10:
<source>:7:8: warning: '*(int*)((char*)&y + offsetof(const Y,
Y::o.std::optional<int>::<unnamed>.std::_Optional_base<int, true,
true>::<unnamed>))' is used uninitialized [-Wuninitialized]
    7 | struct Y {
      |        ^
<source>: In function 'void test()':
<source>:18:13: note: 'y' declared here
   18 |     Y const y;
      |             ^

Most similar to #80635 and #86465, I think? Although this is -Wuninitialized,
not -Wmaybe-uninitialized.

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

end of thread, other threads:[~2022-11-28 22:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-10 23:14 [Bug c++/107206] New: Bogus -Wuninitialized in std::optional ed at catmur dot uk
2022-10-11  8:16 ` [Bug libstdc++/107206] " rguenth at gcc dot gnu.org
2022-10-11 10:10 ` redi at gcc dot gnu.org
2022-10-11 10:20 ` rguenth at gcc dot gnu.org
2022-10-11 10:22 ` [Bug tree-optimization/107206] " rguenth at gcc dot gnu.org
2022-10-14 16:53 ` jamborm at gcc dot gnu.org
2022-10-16 17:27 ` rguenther at suse dot de
2022-10-19 12:59 ` cvs-commit at gcc dot gnu.org
2022-11-16 12:13 ` cvs-commit at gcc dot gnu.org
2022-11-16 12:14 ` jamborm at gcc dot gnu.org
2022-11-28 22:22 ` 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).