aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc/invoke.texi
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2024-01-25 12:08:14 -0500
committerMarek Polacek <polacek@redhat.com>2024-01-30 13:18:32 -0500
commitf2061b2a9641c2228d4e2d86f19532ad7e93d627 (patch)
tree2abec8e50144538a94b4f0dba4f05d43c57099a8 /gcc/doc/invoke.texi
parent24d5e0bf19f27a89a13f64b4b8750dbde89bdaa0 (diff)
downloadgcc-f2061b2a9641c2228d4e2d86f19532ad7e93d627.zip
gcc-f2061b2a9641c2228d4e2d86f19532ad7e93d627.tar.gz
gcc-f2061b2a9641c2228d4e2d86f19532ad7e93d627.tar.bz2
c++: avoid -Wdangling-reference for std::span-like classes [PR110358]
Real-world experience shows that -Wdangling-reference triggers for user-defined std::span-like classes a lot. We can easily avoid that by considering classes like template<typename T> struct Span { T* data_; std::size len_; }; to be std::span-like, and not warning for them. Unlike the previous patch, this one considers a non-union class template that has a pointer data member and a trivial destructor as std::span-like. PR c++/110358 PR c++/109640 gcc/cp/ChangeLog: * call.cc (reference_like_class_p): Don't warn for std::span-like classes. gcc/ChangeLog: * doc/invoke.texi: Update -Wdangling-reference description. gcc/testsuite/ChangeLog: * g++.dg/warn/Wdangling-reference18.C: New test. * g++.dg/warn/Wdangling-reference19.C: New test. * g++.dg/warn/Wdangling-reference20.C: New test.
Diffstat (limited to 'gcc/doc/invoke.texi')
-rw-r--r--gcc/doc/invoke.texi14
1 files changed, 14 insertions, 0 deletions
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 819a75d..eb931b9 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -3916,6 +3916,20 @@ where @code{std::minmax} returns @code{std::pair<const int&, const int&>}, and
both references dangle after the end of the full expression that contains
the call to @code{std::minmax}.
+The warning does not warn for @code{std::span}-like classes. We consider
+classes of the form:
+
+@smallexample
+template<typename T>
+struct Span @{
+ T* data_;
+ std::size len_;
+@};
+@end smallexample
+
+as @code{std::span}-like; that is, the class is a non-union class template
+that has a pointer data member and a trivial destructor.
+
This warning is enabled by @option{-Wall}.
@opindex Wdelete-non-virtual-dtor