Debian Codegraph @

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

raw
1 // { dg-do compile { target c++17 } }
2 // { dg-additional-options "-Wdangling-reference" }
3 // { dg-skip-if "requires hosted libstdc++ for string" { ! hostedlib } }
4 // Check that we warn here even without -Wsystem-headers.
5
6 #include <optional>
7 #include <string>
8
9 auto f() -> std::optional<std::string>;
10
11 void
12 g ()
13 {
14 for (char c : f().value()) { (void) c; } // { dg-warning "dangling reference" "" { target c++20_down } }
15 }