From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 873393858D32; Thu, 27 Apr 2023 06:36:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 873393858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682577418; bh=ALvuJb486iAo5vvMhyYX46zevmah+/7ZoM70ccyMaP8=; h=From:To:Subject:Date:From; b=L/gglc91R7tXI1fLu/0iaF2uJcnKDhh7S30JMzB1eTF+JDLglPY2ekgcW0o5DISXc /Vdt8eWgZcS6eAEqavqxB1ltreaFHAdXNgAnzB+85Oi0BbbyAkPaAX4k4y+O8bYP5W whg8RJOuppt2yLfpGvzRszv5Q81nTY6EeVVQ159o= From: "carlosgalvezp at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes Date: Thu, 27 Apr 2023 06:36:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: carlosgalvezp at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109642 Bug ID: 109642 Summary: False Positive -Wdangling-reference with std::span-like classes Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: carlosgalvezp at gmail dot com Target Milestone: --- Hi, We are bumping our GCC installation from 6910cad55ffc330dc9767d2c8e0b66ccfa4134af to cc035c5d8672f87dc8c2756d9f8367903aa72d93 (GCC 13.1 release), and are now getting a lot of False Positives from code that looks like this: #include #include template struct MySpan { MySpan(T* data, std::size_t size) :=20 data_(data), size_(size) {} T& operator[](std::size_t idx) { return data_[idx]; } private: T* data_; std::size_t size_; }; template MySpan make_my_span(T const(&x)[n]) { return MySpan(std::begin(x), n); } template std::span make_span(T const(&x)[n]) { return std::span(std::begin(x), n); } int main() { int x[10]{}; int const& y{make_my_span(x)[0]}; int const& y2{make_span(x)[0]}; } Godbolt: https://godbolt.org/z/Pf6jsezoP I.e. when using std::span, GCC is happy, but when using our own implementat= ion of span (since we can't enable C++20 yet in our project due to reasons), th= en it complains about dangling reference. Clang trunk does not warn about this. It warns both about non-const and const references.=