libstdc++: suppress -Wdangling-reference with operator| [PR111410]
It seems to me that we should exclude std::ranges::views::__adaptor::operator| from the -Wdangling-reference warning. It's commonly used when handling ranges. PR c++/111410 libstdc++-v3/ChangeLog: * include/std/ranges: Add #pragma to disable -Wdangling-reference with std::ranges::views::__adaptor::operator|. gcc/testsuite/ChangeLog: * g++.dg/warn/Wdangling-reference17.C: New test.
This commit is contained in:
parent
17473a93cf
commit
7db802d972
2 changed files with 18 additions and 0 deletions
15
gcc/testsuite/g++.dg/warn/Wdangling-reference17.C
Normal file
15
gcc/testsuite/g++.dg/warn/Wdangling-reference17.C
Normal file
|
@ -0,0 +1,15 @@
|
|||
// PR c++/111410
|
||||
// { dg-do compile { target c++20 } }
|
||||
// { dg-options "-Wdangling-reference" }
|
||||
|
||||
#include <vector>
|
||||
#include <ranges>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::vector v{1, 2, 3, 4, 5};
|
||||
for (auto i : std::span{v} | std::views::take(1))
|
||||
{
|
||||
(void) i;
|
||||
}
|
||||
}
|
|
@ -942,6 +942,8 @@ namespace views::__adaptor
|
|||
concept __is_range_adaptor_closure
|
||||
= requires (_Tp __t) { __adaptor::__is_range_adaptor_closure_fn(__t, __t); };
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-reference"
|
||||
// range | adaptor is equivalent to adaptor(range).
|
||||
template<typename _Self, typename _Range>
|
||||
requires __is_range_adaptor_closure<_Self>
|
||||
|
@ -961,6 +963,7 @@ namespace views::__adaptor
|
|||
return _Pipe<decay_t<_Lhs>, decay_t<_Rhs>>{std::forward<_Lhs>(__lhs),
|
||||
std::forward<_Rhs>(__rhs)};
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
// The base class of every range adaptor non-closure.
|
||||
//
|
||||
|
|
Loading…
Add table
Reference in a new issue