Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wdangling-reference15.C

raw
1 // PR c++/111607
2 // { dg-do compile { target c++20 } }
3 // { dg-options "-Wdangling-reference" }
4
5 #include <variant>
6
7 struct S {
8 constexpr S(int i_) : i(i_) {}
9 S(S const &) = delete;
10 S & operator=(S const &) = delete;
11 S(S &&) = delete;
12 S & operator=(S &&) = delete;
13 int i;
14 };
15
16 struct A {
17 S s{0};
18 };
19
20 using V = std::variant<A>;
21
22 consteval auto f(V const & v) {
23 auto const & s = std::visit([](auto const & v) -> S const & { return v.s; }, v); // { dg-bogus "dangling reference" }
24 return s.i;
25 }
26
27 int main() {
28 constexpr V a{std::in_place_type<A>};
29 constexpr auto i = f(a);
30 return i;
31 }