c++: avoid -Wdangling-reference for std::span-like classes [PR110358]
commitf2061b2a9641c2228d4e2d86f19532ad7e93d627
authorMarek Polacek <polacek@redhat.com>
Thu, 25 Jan 2024 17:08:14 +0000 (25 12:08 -0500)
committerMarek Polacek <polacek@redhat.com>
Tue, 30 Jan 2024 18:18:32 +0000 (30 13:18 -0500)
tree2abec8e50144538a94b4f0dba4f05d43c57099a8
parent24d5e0bf19f27a89a13f64b4b8750dbde89bdaa0
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.
gcc/cp/call.cc
gcc/doc/invoke.texi
gcc/testsuite/g++.dg/warn/Wdangling-reference18.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wdangling-reference19.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wdangling-reference20.C [new file with mode: 0644]