std::span is a view and therefore should be treated as a reference
wrapper class for the purposes of -Wdangling-reference. I'm not sure
there's a pattern that we could check for.
PR c++/107532
gcc/cp/ChangeLog:
* call.cc (reference_like_class_p): Check for std::span.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wdangling-reference10.C: New test.
tree name = DECL_NAME (tdecl);
return (name
&& (id_equal (name, "reference_wrapper")
+ || id_equal (name, "span")
|| id_equal (name, "ref_view")));
}
for (tree fields = TYPE_FIELDS (ctype);
--- /dev/null
+// PR c++/107532
+// { dg-do compile { target c++20 } }
+// { dg-options "-Wdangling-reference" }
+
+#include <span>
+#include <vector>
+
+void f(const std::vector<int>& v)
+{
+ const int& r = std::span<const int>(v)[0]; // { dg-bogus "dangling reference" }
+ (void) r;
+}