Debian Codegraph @

gcc/testsuite/g++.dg/torture/pr106922.C

raw
1 // { dg-do compile }
2 // { dg-require-effective-target c++17 }
3 // { dg-additional-options "-Wall" }
4 // { dg-skip-if "requires hosted libstdc++ for vector" { ! hostedlib } }
5 // -O1 doesn't iterate VN and thus has bogus uninit diagnostics
6 // { dg-skip-if "" { *-*-* } { "-O1" } { "" } }
7
8 // The testcase still emits bogus diagnostics with the pre-C++11 ABI
9 #undef _GLIBCXX_USE_CXX11_ABI
10 #define _GLIBCXX_USE_CXX11_ABI 1
11
12 #include <vector>
13
14 // When the library is not dual-ABI and defaults to old just compile
15 // an empty TU
16 #if _GLIBCXX_USE_CXX11_ABI
17
18 #include <optional>
19 template <class T>
20 using Optional = std::optional<T>;
21
22 #include <sstream>
23
24 struct MyOptionalStructWithInt {
25 int myint; /* works without this */
26 Optional<std::vector<std::string>> myoptional;
27 };
28
29 struct MyOptionalsStruct {
30 MyOptionalStructWithInt external1;
31 MyOptionalStructWithInt external2;
32 };
33
34 struct MyStruct { };
35 std::ostream &operator << (std::ostream &os, const MyStruct &myStruct);
36
37 std::vector<MyStruct> getMyStructs();
38
39 void test()
40 {
41 MyOptionalsStruct externals;
42 MyOptionalStructWithInt internal1;
43 MyOptionalStructWithInt internal2;
44
45 std::vector<MyStruct> myStructs;
46 myStructs = getMyStructs();
47
48 for (const auto& myStruct : myStructs)
49 {
50 std::stringstream address_stream;
51 address_stream << myStruct;
52 internal1.myint = internal2.myint = 0;
53 externals.external1 = internal1;
54 externals.external2 = internal2;
55 externals.external2 = internal2;
56 }
57 }
58 #endif