aboutsummaryrefslogtreecommitdiff
path: root/libphobos/src/std/algorithm
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2022-10-26 21:15:53 -0400
committerMarek Polacek <polacek@redhat.com>2022-10-28 13:40:41 -0400
commite583c86f49b9ef6991b25308a0ad60de9697f24a (patch)
tree30308ec5aaae1eea9944a8ad734a661c7ef209a3 /libphobos/src/std/algorithm
parent38a628f52cf0ff5db6708578248484d50a50b366 (diff)
downloadgcc-e583c86f49b9ef6991b25308a0ad60de9697f24a.zip
gcc-e583c86f49b9ef6991b25308a0ad60de9697f24a.tar.gz
gcc-e583c86f49b9ef6991b25308a0ad60de9697f24a.tar.bz2
c++: -Wdangling-reference and system headers
I got this testcase: auto f() -> std::optional<std::string>; for (char c : f().value()) { } which has a dangling reference: std::optional<T>::value returns a reference to the contained value, but here it's the f() temporary. We warn, which is great, but only with -Wsystem-headers, because the function comes from a system header and warning_enabled_at used in do_warn_dangling_reference checks diagnostic_report_warnings_p, which in this case returned false so we didn't warn. Fixed as below. I could also override dc_warn_system_headers so that the warning is enabled in system headers always. With that, I found one issue in libstdc++: libstdc++-v3/include/bits/fs_path.h:1265:15: warning: possibly dangling reference to a temporary [-Wdangling-reference] 1265 | auto& __last = *--end(); | ^~~~~~ which looks like a true positive as well. gcc/cp/ChangeLog: * call.cc (maybe_warn_dangling_reference): Enable the warning in system headers if the decl isn't in a system header. gcc/testsuite/ChangeLog: * g++.dg/warn/Wdangling-reference4.C: New test.
Diffstat (limited to 'libphobos/src/std/algorithm')
0 files changed, 0 insertions, 0 deletions