diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2021-09-29 21:19:49 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2021-10-07 14:55:35 +0100 |
commit | 9b239d05ffd5a17ede44abd55bc6622c6e279868 (patch) | |
tree | 9d80b0afbf62a56f873f4e731669d7fef3747f87 /gcc/testsuite | |
parent | 44b61586d8640b79e78cfdb6a555200ccee8df77 (diff) | |
download | gcc-9b239d05ffd5a17ede44abd55bc6622c6e279868.zip gcc-9b239d05ffd5a17ede44abd55bc6622c6e279868.tar.gz gcc-9b239d05ffd5a17ede44abd55bc6622c6e279868.tar.bz2 |
c++: Do not warn about lifetime of std::initializer_list<T>& [PR102482]
An initializer-list constructor taking a non-const lvalue cannot be
called with a temporary, so the array's lifetime probably doesn't end
with the full expression. -Winit-list-lifetime should not warn for that
case.
PR c++/102482
gcc/cp/ChangeLog:
* init.c (maybe_warn_list_ctor): Do not warn for a reference to
a non-const std::initializer_list.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Winit-list5.C: New test.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Winit-list5.C | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/warn/Winit-list5.C b/gcc/testsuite/g++.dg/warn/Winit-list5.C new file mode 100644 index 0000000..07b3a69 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Winit-list5.C @@ -0,0 +1,61 @@ +// PR c++/102482 +// { dg-do compile { target c++11 } } +// Test we don't warn for non-const lvalue refs. + +#include <initializer_list> + +struct X { }; + +struct span +{ + span(std::initializer_list<int>& il) + : begin(il.begin()) // { dg-bogus "initializer_list" } + { } + + const int* begin; +}; + +struct span_warn +{ + span_warn(std::initializer_list<int> il) + : begin(il.begin()) // { dg-warning "initializer_list" } + { } + + const int* begin; +}; + +struct span_warn2 +{ + span_warn2(std::initializer_list<int>&& il) + : begin(il.begin()) // { dg-warning "initializer_list" } + { } + + const int* begin; +}; + +struct span_warn3 +{ + span_warn3(std::initializer_list<int> const& il) + : begin(il.begin()) // { dg-warning "initializer_list" } + { } + + const int* begin; +}; + +struct span_warn4 +{ + span_warn4(std::initializer_list<int> const il) + : begin(il.begin()) // { dg-warning "initializer_list" } + { } + + const int* begin; +}; + +struct span_warn5 +{ + span_warn5(std::initializer_list<int> const&& il) + : begin(il.begin()) // { dg-warning "initializer_list" } + { } + + const int* begin; +}; |