public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes
@ 2023-04-27  6:36 carlosgalvezp at gmail dot com
  2023-04-27  7:03 ` [Bug c++/109642] " pinskia at gcc dot gnu.org
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: carlosgalvezp at gmail dot com @ 2023-04-27  6:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642

            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 <iterator>
#include <span>

template <typename T>
struct MySpan
{
 MySpan(T* data, std::size_t size) : 
    data_(data),
    size_(size)
 {}

 T& operator[](std::size_t idx) { return data_[idx]; }

private:
    T* data_;
    std::size_t size_;
};

template <typename T, std::size_t n>
MySpan<T const> make_my_span(T const(&x)[n])
{
    return MySpan(std::begin(x), n);
}

template <typename T, std::size_t n>
std::span<T const> 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 implementation
of span (since we can't enable C++20 yet in our project due to reasons), then
it complains about dangling reference. Clang trunk does not warn about this.

It warns both about non-const and const references.

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2024-05-01 17:18 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-27  6:36 [Bug c++/109642] New: False Positive -Wdangling-reference with std::span-like classes carlosgalvezp at gmail dot com
2023-04-27  7:03 ` [Bug c++/109642] " pinskia at gcc dot gnu.org
2023-04-27  7:09 ` carlosgalvezp at gmail dot com
2023-04-27 15:49 ` mpolacek at gcc dot gnu.org
2023-04-27 19:20 ` carlosgalvezp at gmail dot com
2023-04-28 13:00 ` mpolacek at gcc dot gnu.org
2023-04-28 14:08 ` carlosgalvezp at gmail dot com
2023-05-02 19:49 ` cvs-commit at gcc dot gnu.org
2023-06-21 18:43 ` pinskia at gcc dot gnu.org
2023-06-21 18:51 ` mpolacek at gcc dot gnu.org
2023-06-21 19:06 ` barry.revzin at gmail dot com
2024-01-17 12:16 ` miro.palmu at helsinki dot fi
2024-01-19 17:35 ` mpolacek at gcc dot gnu.org
2024-01-19 23:32 ` mpolacek at gcc dot gnu.org
2024-01-22 20:52 ` mpolacek at gcc dot gnu.org
2024-01-22 21:16 ` cvs-commit at gcc dot gnu.org
2024-01-30 18:32 ` mpolacek at gcc dot gnu.org
2024-01-30 18:38 ` lopresti at gmail dot com
2024-01-30 18:42 ` mpolacek at gcc dot gnu.org
2024-03-01 20:55 ` cvs-commit at gcc dot gnu.org
2024-05-01 17:18 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).