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/cp | |
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/cp')
-rw-r--r-- | gcc/cp/init.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 1426f9a..771a19b 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -749,8 +749,15 @@ maybe_warn_list_ctor (tree member, tree init) || !is_list_ctor (current_function_decl)) return; - tree parms = FUNCTION_FIRST_USER_PARMTYPE (current_function_decl); - tree initlist = non_reference (TREE_VALUE (parms)); + tree parm = FUNCTION_FIRST_USER_PARMTYPE (current_function_decl); + parm = TREE_VALUE (parm); + tree initlist = non_reference (parm); + + /* Do not warn if the parameter is an lvalue reference to non-const. */ + if (TYPE_REF_P (parm) && !TYPE_REF_IS_RVALUE (parm) + && !CP_TYPE_CONST_P (initlist)) + return; + tree targs = CLASSTYPE_TI_ARGS (initlist); tree elttype = TREE_VEC_ELT (targs, 0); |