Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wuninitialized-33.C

raw
1 // PR102801
2 // { dg-do compile }
3 // { dg-require-effective-target c++17 }
4 // { dg-options "-O2 -Wall" }
5 // { dg-skip-if "requires hosted libstdc++ for string" { ! hostedlib } }
6
7 #include <algorithm>
8 #include <memory>
9 #include <optional>
10 #include <string>
11 #include <utility>
12 #include <vector>
13
14 class C {
15 bool b{}; // { dg-bogus "uninitialized" }
16
17 struct Shared {};
18 using SharedPtr = std::shared_ptr<const Shared>;
19
20 SharedPtr shared;
21
22 public:
23 C() = delete;
24 C(bool bIn) : b(bIn) {}
25 ~C();
26 int someMethod() const;
27 };
28
29 using OptC = std::optional<C>;
30
31 class C2 {
32 OptC c;
33 public:
34 C2() = default;
35 C2(const C &cIn) : c(cIn) {}
36 ~C2();
37 void operator()() const;
38 void swap(C2 &o) { std::swap(c, o.c); }
39 };
40
41
42 template <typename T>
43 class Q {
44 std::vector<T> queue;
45 public:
46 void Add(std::vector<T> &items) {
47 for (T & item : items) {
48 queue.push_back(T());
49 item.swap(queue.back());
50 }
51 }
52 void Exec();
53 };
54
55 extern void foo(Q<C2> & q, std::vector<C2> &items);
56 void foo(Q<C2> & q, std::vector<C2> &items) { q.Add(items); q.Exec(); }